Closed
Description
Use case
The current implementation of the AppSyncGraphQLResolver
introduced in #3999 exposes the current event
and context
to route handlers via separate arguments.
This pattern was used in the first AppSync Events API resolver, but since then we evolved the standard to instead expose them as a single object in the Bedrock Agents resolver.
We should align this resolver to the Bedrock Agents one.
Solution/User Experience
The event
and context
should be available to route handlers like this:
import { Logger } from '@aws-lambda-powertools/logger';
import { AppSyncGraphQLResolver } from '@aws-lambda-powertools/event-handler/appsync-graphql';
import type { Context } from 'aws-lambda';
const logger = new Logger({
serviceName: 'serverlessAirline',
});
const app = new AppSyncGraphQLResolver({ logger });
app.onQuery<{ id: string }>('getTodo', async ({ id }, {
event
context
}) => {
const { headers } = event.request; // (1)!
const { awsRequestId } = context;
logger.info('headers', { headers, awsRequestId });
// Simulate fetching a todo from a database or external service
return {
id,
title: 'Todo Title',
completed: false,
};
});
export const handler = async (event: unknown, context: Context) =>
app.resolve(event, context);
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