Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I export AWS AppSync resolvers?

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.

like image 877
brendangibson Avatar asked Nov 15 '18 04:11

brendangibson


People also ask

What are resolvers in AppSync?

Resolvers provide the implementation for how AppSync processes queries and mutations. They connect the GraphQL schema, the abstract definition of the API, and the services that provide the data, such as a database or a Lambda function. In practice, most of AppSync development is spent writing resolvers.

What are resolvers AWS?

Data sources and resolvers are how AWS AppSync translates GraphQL requests and fetches information from your AWS resources. AWS AppSync has support for automatic provisioning and connections with certain data source types.

How do I add resolver to AppSync?

Adding a Resolver for MutationsAWS AppSync automatically converts arguments defined in the addTodo field from your GraphQL schema into DynamoDB operations. The previous example stores records in DynamoDB using a key of id , which is passed through from the mutation argument as $ctx.args.id .

How do I query AWS AppSync?

In the AWS AppSync console choose the Queries tab on the left hand side. The pane on the right side enables you to click through the operations, including queries, mutations, and subscriptions that your schema has exposed. Choose the Mutation node to see a mutation.


2 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
like image 184
alditis Avatar answered Sep 19 '22 10:09

alditis


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:

  • https://read.acloud.guru/deploy-a-graphql-service-on-aws-with-the-serverless-framework-7af8fc22a01d

  • https://read.acloud.guru/deploy-an-aws-appsync-graphql-api-with-amazon-cloudformation-9a783fdd8491

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

like image 44
Michael Willingham Avatar answered Sep 19 '22 10:09

Michael Willingham