AppSync default or pattern-based resolver mapping


Does AWS AppSync support a way to map Queries/Mutations/Fields to a resolver without having to define everything as a 1:1 mapping? I was thinking something like a default or pattern-based resolver mapping, similar to how API Gateway allows you to map entire URL patterns to a Lambda function.

I've been using AWS AppSync for a project that has grown quite large. The vast majority of our GraphQL queries and mutations map to a single Lambda function, which uses a router to match requests to the correct logic. This is similar to how many webapp frameworks are designed. Since all our resolver mappings are 1:1, we're accumulating a giant Cloudformation template that grows with every new Query/Mutation. Updating our Lambda function requires long deployment times because all the resolver mappings must be updated too.

I've searched AWS AppSync documentation and found no reference to such a feature. Does anyone know if a solution exists or have any suggestions?

1 Answer

AWS AppSync does not currently provide a way to map queries/mutations/fields to a resolver without having to define everything as a 1:1 mapping. Each resolver must be explicitly defined in the schema.

However, you can simplify your CloudFormation template by using CloudFormation macros to generate the resolver mappings for you. This can help reduce the amount of boilerplate code and make the template more manageable.

Alternatively, you can use AWS Amplify to generate the schema and resolver mappings for you based on your backend logic. Amplify provides a CLI that can introspect your backend code and generate a GraphQL schema and resolvers automatically. This can save a significant amount of time and reduce the need for manual updates to the schema and resolver mappings.

Overall, while there is no default or pattern-based resolver mapping feature in AWS AppSync, there are tools available to help simplify the management of resolver mappings.

answered a year ago
  • Do you know if the AWS AppSync team has any plans to support this? It'd be a great feature.

    The suggestion of reducing boilerplate with CloudFormation macros helps, but doesn't solve the problem of infrastructure growing as the GraphQL API expands. Eventually, deploying a small update to a single Lambda function could require updating hundreds of AppSync resolvers depending on it. This is not a problem with API Gateway, a similar product.

    One suggestion: update the CreateResolver API [1] to support wildcard patterns in the typeName and fieldName inputs.

    Example 1: Attach a resolver to all mutations

    typeName = Mutation
    fieldName = *

    Example 2: Attach a resolver to all matching pattern Query.user*

    typeName = Query
    fieldName = user*


You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions