Skip to content

Feature request: expose event & context as object in AppSync GraphQL #4112

Closed
@dreamorosi

Description

@dreamorosi

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

Future readers

Please react with 👍 and your use case to help us understand customer demand.

Metadata

Metadata

Assignees

Labels

completedThis item is complete and has been merged/shippedevent-handlerThis item relates to the Event Handler Utilityfeature-requestThis item refers to a feature request for an existing or new utility

Type

No type

Projects

Status

Shipped

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions