Skip to content

AppSync default or pattern-based resolver mapping

0

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?

2 Answers
0

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.

AWS
answered 3 years 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*
    

    [1] https://docs.aws.amazon.com/appsync/latest/APIReference/API_CreateResolver.html

0

Now we've run into precisely this problem. We had started using AppSync assuming that this would eventually be fixed by AWS or that it would be a "good problem to have" after our product had grown. Well, it's not a good problem to have. We have a single shared Lambda serving most of our AppSync resolvers. A simple code update requires a long Cloudformation update, simply to repoint tons of AppSync resolvers to the new Lambda. In fact, we're closing in on the Cloudformation stack resource limit and need to workaround that somehow.

The problem is so bad that we're discussing switching from AppSync to API Gateway. This is much more than a simple annoyance. AppSync team: please think about adding support for wildcard resolver matching similar to API Gateway. I'm sure there are others with our use case that stay silent and endure the pain.

answered 2 years ago

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.