Skip to content

Feature request: support onQuery and onMutation resolvers in AppSync GraphQL #4110

Closed
@dreamorosi

Description

@dreamorosi

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

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