appsync
AWS AppSync Integration
AWS AppSync is a managed serverless GraphQL service that simplifies application development by letting you create a flexible API to securely access, manipulate, and combine data from one or more data sources.
What is AWS AppSync?
AWS AppSync allows you to create serverless GraphQL APIs. Applications interact with AppSync by sending GraphQL queries, mutations, or subscriptions. AppSync then executes these requests against your configured data sources (such as DynamoDB, Aurora Serverless, OpenSearch, AWS Lambda, or HTTP endpoints).
Resolvers in AWS AppSync
Resolvers are the connectors that link GraphQL fields to data sources. When a client performs a GraphQL operation, AppSync uses resolvers to fetch the requested data or execute business logic.
AppSync supports two types of resolvers:
- Unit Resolvers: Map a single GraphQL field to a single data source.
- Pipeline Resolvers: Execute multiple operations (functions) sequentially against one or more data sources.
Resolvers can be authored in:
- JavaScript (APPSYNC_JS runtime): Modern, recommended approach that allows writing resolver functions in JavaScript.
- VTL (Velocity Template Language): Legacy templates for request and response mapping.
Nuxt Precognition for AppSync
Since GraphQL has a single HTTP POST endpoint (/graphql) and returns standard 200 OK status codes even for validation or execution errors, implementing the standard HTTP Precognition protocol (which relies on 204 and 422 status codes) requires a bridge.
To make Nuxt Precognition work seamlessly with AWS AppSync, we can either:
- Pass Precognition metadata via GraphQL request headers.
- Pass Precognition arguments directly inside the GraphQL mutation inputs.
In this section, we'll explore how Nuxt Precognition was designed to support AppSync by adapting the headers, handling response payloads, and using dedicated strategies for:
- AppSync JS Resolvers: Executing lightweight validation directly within the AppSync runtime using the
@sot1986/appsync-precognitionhelper library. - AppSync Lambda Functions: Delegating complex or database-backed validation to AWS Lambda.