12

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.

brendangibson
  • 2,377
  • 2
  • 21
  • 36

4 Answers4

8

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
alditis
  • 4,633
  • 3
  • 49
  • 76
  • im use - npm i export-appsync -g - export-appsync -a api-id -k access-key-id -s secret-access-key -r region -o output-dir – Yanov Feb 10 '22 at 08:03
4

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

4

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.

melaku-z
  • 41
  • 1
  • 4
  • Using that, good to get the work done. I had to modify it to be able to export both functions and datasources as well. Very helpful – saintjab Jan 06 '23 at 11:53
3

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.

Gabe Hollombe
  • 7,847
  • 4
  • 39
  • 44
  • That's a reasonable hypothesis, and I tried that too. However the default resolvers are not returned but clearly they have to be there behind the scenes are the API wouldn't work. This is a bit of a flaky area. Wow -- even weirder. What you have to do is manually attach a resolver for each field on the type. So the default resolvers show up in the UI, and once you attach them you can export them. But again, those defaults had to be there originally. This is one of the more half-baked AWS services I've dealt with. It's good to work with the new ones ;). – John Lockwood May 02 '20 at 15:02