7

When using AWS Amplify with a dynamodb backend, it's possible to update the AppSync schema and resolvers by modifying the files locally and then executing amplify push.

I'm using RDS (added it with amplify api add-graphql-datasource as described in the documentation). Queries and resolvers are setup in AppSync automatically. When I update the Aurora RDS schema, I run amplify api add-graphql-datasource again to update queries and resolvers.

But how do I add new queries/mutations and bind them to new resolvers (defined in vtl files on localhost), using the amplify CLI?

I figured out how to do it by using the AppSync Web console. I modify the schema and create resolvers in AppSync, then use amplify codegen to update App.ts, queries.ts, etc. However, this approach is bad for at least two reasons.

  1. When working with multiple environments, changes to each environment has to be done manually via the AppSync console, which is difficult for larger projects.
  2. amplify codegen doesn't update the schema.graphql file on localhost.
  3. Executing amplify push after making changes to AppSync over uses the schema defined on localhost and overwrites the schema defined in the AppSync console.
  4. Custom resolvers in app/amplify/backend/<backend_name>/resolvers are not synchronized with AppSync
  5. the stack file is not updated automatically.

Am I going about this the wrong way? Is there a better way of updating schema/resolvers using amplify CLI when using and RDS backend?

Thank you!

halfdanr
  • 373
  • 4
  • 11
  • 2
    Did you manage to solve it? We are about to do a AWS migration and we are almost going to ditch Amplify just for this very reason. Seems unfinished for SQL and too focused on DynamoDB. – sebastianf182 Jul 09 '20 at 10:05
  • 2
    I agree. Most of the cool amplify features are unfortunately not supported for RDS. I did manage to get a decent workflow going though. – halfdanr Sep 15 '20 at 07:38

1 Answers1

0

OK,

  1. When working with multiple environments, changes to each environment has to be done manually via the AppSync console, which is difficult for larger projects.

Keep a git branch for each environment. First make changes in dev branch and run amplify push to push the changes to the AppSync dev project. When it's time to bring the changes to staging, do this:

  1. cd app && amplify env checkout staging && amplify env pull --restore && amplify status
  2. git checkout staging && git merge dev
  3. amplify push
  1. amplify codegen doesn't update the schema.graphql file on localhost.

True, but it's not what amplify codegen is supposed to do, so I'm not sure what I wrote this. The documentation is quite clear:

Codegen helps you generate native code for iOS and Android, as well as the generation of types for Flow and TypeScript. It can also generate GraphQL statements (queries, mutations, and subscriptions) so that you don’t have to hand code them.

..next!

  1. Executing amplify push after making changes to AppSync over uses the schema defined on localhost and overwrites the schema defined in the AppSync console. I'm not sure what I meant to say here. But the workflow that ended up working for me is
  1. update schema.graphql on localhost
  2. create resolver files on localhost
  3. amplify push to update AppSync
  1. Custom resolvers in app/amplify/backend/<backend_name>/resolvers are not synchronized with AppSync

I was wrong. If you create the required resolver files properly, the AppSync resolvers are configures properly when running amplify push. My mistake was that I forgot to create the response mapper template files.

  1. the stack file is not updated automatically.

This is true, but you quickly get used to editing the stack file manually. Indeed it would be nice if there was a quick add feature, but since you're just adding a json file, it'd be easy to throw together a quick python script to do this for you.

halfdanr
  • 373
  • 4
  • 11