How do I export AWS AppSync resolvers?

Viewed 2589

I have setup AppSync with a Schema and Resolvers. I can export the Schema to a file, but I cannot see how to export the Resolvers.

I want to store these in a file so that I can source control them. They contain plenty of SQL code that I don't want to lose.

4 Answers

Command template: TYPE_NAME values: Mutation, Query and Subscription.

aws appsync list-resolvers --api-id YOUR_API_ID --type-name TYPE_NAME >> YOUR_FILE.txt

Examples: With YOUR_API_ID = d5gebysm3 (The original length is 26 in my case)

aws appsync list-resolvers --api-id d5gebysm3 --type-name Mutation >> Mutation.txt
aws appsync list-resolvers --api-id d5gebysm3 --type-name Query >> Query.txt
aws appsync list-resolvers --api-id d5gebysm3 --type-name Subscription >> Subscription.txt

Before you go any farther, I would recommend you look into managing your AppSync resources with CloudFormation. CloudFormation templates can easily be saved in source control.

AppSync & CloudFormation Tutorials:

Or if your resolvers aren't doing anything custom, you can use Amplify's GraphQL Transformer. This allows you to annotate your schema and it will automatically generate resolvers from the annotations. Then you can put the annotated schema into source control. Documentation:

https://aws-amplify.github.io/docs/js/api#using-graphql-transformers

The nice thing about AWS is that there's probably an API endpoint for what you're looking for.

In this case, you can access the list of resolvers via the ListResolvers API endpoint, and you can retrieve a specific resolver via the GetResolver API endpoint.

There is a node.js package specifically made for this: export-appsync. But in the long term, it's easier to source control your schema and resolvers of you work from either serverless framework (serverless.com), from cloudformation or the AWS amplify framework.

Related