AWS AppSync, GraphQL and AWS Amplify for Developers: Resolvers, Subscriptions, Hosting and Full-Stack Apps
GraphQL in One Minute
GraphQL lets the client ask for exactly the fields it needs in one request to one endpoint, instead of calling many REST endpoints and getting extra data.
graphql
type Task {
id: ID!
title: String!
done: Boolean!
owner: String
}
type Query {
getTask(id: ID!): Task
listTasks(limit: Int, nextToken: String): TaskConnection
}
type TaskConnection { items: [Task], nextToken: String }
type Mutation {
createTask(title: String!): Task
completeTask(id: ID!): Task
}
type Subscription {
onCreateTask: Task @aws_subscribe(mutations: ["createTask"])
}
graphql
query {
listTasks(limit: 10) { items { id title done } }
}
| Operation | Meaning |
| Query | Read data |
| Mutation | Change data |
| Subscription | Real-time updates pushed to clients over WebSockets when a mutation happens |
What AppSync Is
AWS AppSync is a managed GraphQL (and Pub/Sub) service. You provide a schema, attach data sources, and write resolvers that map each field to a data source. AppSync handles scaling, WebSocket subscriptions, caching and security.
| Part | Meaning |
| Schema | Types, queries, mutations, subscriptions |
| Data sources | DynamoDB, Lambda, HTTP endpoints, OpenSearch, Aurora (Data API), EventBridge, RDS, and NONE (local resolvers) |
| Resolvers | Code that turns a GraphQL field request into a data source request and shapes the response. JavaScript resolvers (APPSYNC_JS) are the current approach; older VTL mapping templates still exist |
| Pipeline resolvers | Run several functions in sequence (for example check permissions, then read data) |
| Merged APIs and Events API | Combine several APIs. Newer WebSocket pub/sub options (check docs) |
javascript
// JavaScript resolver for Mutation.createTask with a DynamoDB data source
import { util } from "@aws-appsync/utils";
export function request(ctx) {
const id = util.autoId();
return {
operation: "PutItem",
key: util.dynamodb.toMapValues({ id }),
attributeValues: util.dynamodb.toMapValues({
title: ctx.args.title, done: false, owner: ctx.identity.sub, createdAt: util.time.nowISO8601(),
}),
condition: { expression: "attribute_not_exists(id)" },
};
}
export function response(ctx) {
if (ctx.error) util.error(ctx.error.message, ctx.error.type);
return ctx.result;
}
Authorization Modes
| Mode | Use |
| API key | Public or prototype access. Keys expire (up to 365 days) |
| Cognito user pools | Signed-in users and groups, with directives such as @aws_auth(cognito_groups: ["admins"]) or @aws_cognito_user_pools |
| IAM | Backend services and identity pool guests |
| OIDC | Third-party identity providers |
| Lambda authorizer | Custom logic |
- You can enable multiple modes: one default plus additional modes per type or field using directives
- Filter data by owner in resolvers using
ctx.identity.sub so users only see their own items
Subscriptions and Real Time
- Clients subscribe and AppSync pushes results when the linked mutation runs. Good for chat, dashboards, collaboration, live scores
- Use subscription filters so clients get only relevant events
- Subscriptions work only for changes made through AppSync mutations. For changes done elsewhere publish with a mutation (for example from a Lambda function)
Performance
- Server-side caching (per-API or per-resolver) with a TTL
- Batch resolvers (
BatchGetItem) to avoid the N+1 problem
- Use DataLoader-style batching on Lambda resolvers
- Delta sync for offline-capable mobile apps
REST (API Gateway) vs GraphQL (AppSync)
| API Gateway REST/HTTP | AppSync GraphQL |
| Style | Many resource endpoints | One endpoint, client-chosen fields |
| Real time | WebSocket API (build routes) | Built-in subscriptions |
| Best for | Simple CRUD APIs, partner APIs, public REST contracts | Rich client apps with varied data needs, mobile, real-time |
| Data access | Mostly via Lambda or integrations | Direct DynamoDB resolvers without Lambda |
AWS Amplify
Amplify is a set of tools to build and host full-stack web and mobile apps quickly.
| Part | What it does |
| Amplify Hosting | Git-connected CI/CD and hosting (CloudFront + S3 style) for React, Next.js, Vue, Angular and more. Preview environments per pull request, custom domains, SSR support |
| Amplify Gen 2 (code-first backend) | Define backend (auth, data, storage, functions) in TypeScript, deployed with CDK under the hood. Per-developer cloud sandboxes |
| Amplify libraries | JavaScript, Swift, Android and Flutter libraries for Auth (Cognito), Storage (S3), API (AppSync/REST), analytics, push |
| Amplify UI | Prebuilt components such as the Authenticator |
typescript
// amplify/data/resource.ts (Amplify Gen 2 style)
import { a, defineData, type ClientSchema } from "@aws-amplify/backend";
const schema = a.schema({
Task: a.model({ title: a.string().required(), done: a.boolean().default(false) })
.authorization((allow) => [allow.owner()]),
});
export type Schema = ClientSchema<typeof schema>;
export const data = defineData({ schema, authorizationModes: { defaultAuthorizationMode: "userPool" } });
javascript
import { generateClient } from "aws-amplify/data";
const client = generateClient();
await client.models.Task.create({ title: "Learn AppSync" });
const { data: tasks } = await client.models.Task.list();
client.models.Task.onCreate().subscribe({ next: (t) => console.log("new", t) });
Check current docs Amplify changes quickly between generations (Gen 1 CLI and Gen 2). Always follow the current Amplify documentation for exact commands.
Practice Tasks
- Create an AppSync API with a DynamoDB data source and test queries in the console
- Write a JavaScript resolver that stores
ctx.identity.sub as the owner
- Open two browser tabs and watch a subscription deliver a new item
- Protect a mutation to the
admins Cognito group
- Deploy a React app with Amplify Hosting from a Git repository
Conclusion
GraphQL lets clients request exactly the data they need. AppSync provides the managed GraphQL API with resolvers to DynamoDB, Lambda and HTTP sources, multiple authorization modes, caching and real-time subscriptions. Amplify adds hosting, a code-first backend and client libraries for faster full-stack delivery.
Quick Summary: GraphQL; AppSync parts; resolver; auth modes; subscriptions; performance; REST vs GraphQL; Amplify.