Closed
Description
Use case
In addition to registering resolvers with app.resolver()
customers should be able to use a short-hand syntax specific to Mutation and Query operations as described in the initial spec (#1166).
Solution/User Experience
Similar to what was implemented in an earlier version of #3999, we should allow customers to register resolvers like this:
import {
AppSyncGraphQLResolver,
makeId,
} from '@aws-lambda-powertools/event-handler/appsync-graphql';
import type { Context } from 'aws-lambda';
const app = new AppSyncGraphQLResolver();
app.onQuery('getPost', async ({ id }) => {
logger.debug('getPost called', { id });
// Simulate fetching a post from a database or other source
return {
id,
title: `Post Title ${id}`,
content: `Content for post ${id}`,
};
});
app.onMutation('addPost', async (args) => {
logger.debug('addPost called', { args });
const { author, title, content } = args;
// Simulate creating a post in a database or other source
return {
id: makeId(), // Generate a unique ID if not provided
author,
title,
content,
};
});
Alternative solutions
Acknowledgment
- This feature request meets Powertools for AWS Lambda (TypeScript) Tenets
- Should this be considered in other Powertools for AWS Lambda languages? i.e. Python, Java, and .NET
Future readers
Please react with 👍 and your use case to help us understand customer demand.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Shipped