Skip to content

feat(event-handler): expose event & context as object #4113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ class AppSyncGraphQLResolver extends Router {
if (resolverHandlerOptions) {
return resolverHandlerOptions.handler.apply(options?.scope ?? this, [
event.arguments,
event,
context,
{ event, context },
]);
}

Expand Down
12 changes: 8 additions & 4 deletions packages/event-handler/src/types/appsync-graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@ import type { Router } from '../appsync-graphql/Router.js';

type ResolverSyncHandlerFn<TParams = Record<string, unknown>> = (
args: TParams,
event: AppSyncResolverEvent<TParams>,
context: Context
options: {
event: AppSyncResolverEvent<TParams>;
context: Context;
}
) => unknown;

type ResolverHandlerFn<TParams = Record<string, unknown>> = (
args: TParams,
event: AppSyncResolverEvent<TParams>,
context: Context
options: {
event: AppSyncResolverEvent<TParams>;
context: Context;
}
) => Promise<unknown>;

type ResolverHandler<TParams = Record<string, unknown>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,16 @@ describe('Class: AppSyncGraphQLResolver', () => {
it('resolver function has access to event and context', async () => {
// Prepare
const app = new AppSyncGraphQLResolver({ logger: console });
app.onQuery<{ id: string }>('getPost', async ({ id }, event, context) => {
return {
id,
event,
context,
};
});
app.onQuery<{ id: string }>(
'getPost',
async ({ id }, { event, context }) => {
return {
id,
event,
context,
};
}
);

// Act
const event = onGraphqlEventFactory('getPost', 'Query', { id: '123' });
Expand Down
Loading