Welcome to the AWS AppSync JavaScript Samples repository! This collection of samples provides clear and concise examples of utilizing AppSync JavaScript resolvers and functions with various data sources on AWS AppSync. These samples are here to help you get started quickly and enable you to kickstart your own projects.
You can use this repository to get started in both TypeScript and JavaScript solutions.
Documentation | npm - appsync-utils | npm - eslint plugin | Samples | CloudFormation and CDK Examples
Resolvers are the connectors between GraphQL and a data source. They tell AWS AppSync how to translate an incoming GraphQL request into instructions for your backend data source, and how to translate the response from that data source back into a GraphQL response. With AWS AppSync, you can write resolvers using JavaScript, that are run on the AppSync JavaScript (APPSYNC_JS) runtime.
The AppSync JavaScript runtime allows developers to write expressive logic in JavaScript for their business requirements, while using syntax, constructs, and features of the language that they are already familiar with. The runtime has some restrictions from tradeoffs that were made in order for to provide high performance and consistent execution in a secure, multi-tenant environment in a serverless manner. However, the tradeoffs do come with benefits as well, such as no extra costs and lower latencies. For a detailed list of supported features in the runtime, see our resolver reference.
JavaScript resolvers allow you to express your business logic using a simple interface. At its core, your resolvers implement a request
and response
function.
export function request(ctx) {
return {}
}
export function response(ctx) {
return ctx.result
}
- examples: Contains AWS Cloudformation and AWS CDK sample APIs
- samples Contains AppSync resolver and functions templates that you can use in your own APIs
For a full list of supported feature, see our runtime features documentation.
If you are new to AppSync, get an overview in our documentation.
You can get started with one of the CDK examples. Simply clone this repo and start with one of the example directories. Run npm install
to install all the dependencies. You can review the code and run npm run cdk deploy
to launch the application.
The best way to work locally in your own project is to start by installing the two libraries:
- @aws-appsync/utils - Provides type validation and autocompletion in code editors.
- @aws-appsync/eslint-plugin - Catches and fixes problems quickly during development.
Find out more here.
You can also work from the console and edit your code directly the console editor. Note that TypeScript is not supported from the console.
If you have any questions, feedback, or need assistance, please don't hesitate to open an issue on this repository. For general inquiries about AppSync, please visit our Community repository
This library is licensed under the MIT-0 License. See the LICENSE file.