How do I export AWS AppSync resolvers?
Asked Answered
L

4

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.

Lexicon answered 15/11, 2018 at 4:8 Comment(0)
C
7

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
Cyclorama answered 4/2, 2021 at 3:32 Comment(1)
im use - npm i export-appsync -g - export-appsync -a api-id -k access-key-id -s secret-access-key -r region -o output-dirLindly
S
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

Szombathely answered 17/11, 2018 at 0:33 Comment(3)
Thanks for that info. The links detail how to manually create the configuration files. Is there a way to output those files from an existing configuration?Lexicon
Once you've attached the resolvers in the GUI, you can export them using the CLI. aws appsync list-resolvers --api-id <find-your-app-id-on-the-main-api-page-under-integrate-with-your-app> --type-name Post <or-whatever>Reprobation
Links no longer workVersify
K
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.

Koon answered 18/1, 2020 at 7:4 Comment(1)
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 helpfulCoconut
B
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.

Bully answered 15/11, 2018 at 4:12 Comment(1)
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 ;).Reprobation

© 2022 - 2024 — McMap. All rights reserved.