1
votes

I am trying to use Amplify CLI to configure an AWS AppSync API and use it in an Android app. I use this site as the reference: https://aws-amplify.github.io/docs/android/api#appsync-apis-created-using-the-cli

My current workflow is as follows -

  1. I created the app and added the dependencies. I installed CLI at the root directory, ran amplify init and amplify add api and followed the steps. I typed a basic schema in the backend api folder and ran amplify push. (with - Continue? Yes; Update code? Yes; Generate GraphQL statements? Yes)
  2. Next, I tested in the AWS AppSync console by adding more attributes, types, and resolvers.
  3. Once they worked, I made the same changes in the project's Amplify backend folder's schema; Pasted the required resolvers in the backend - resolvers folder; and ran amplify push again. (Continue? Yes; Update Code? Yes; Generate and overwrite GraphQL statements? No; //This is because I didn't want any existing resolvers and mutations to be overwritten)
  4. Then I ran amplify codegen in the root folder of my app and build my app. //This is because even though the changes were seen in the backend after the push, I couldn't find the newly added types in the app unless I ran codegen. i.e The file -(MyApp\app\build\generated\source\appsync\com\amazonaws\amplify\generated\graphql\GetBooksQuery.java) was available only after codegen.

Is this the correct workflow? Especially the 4th step, because the above documentation link doesn't talk about how to see the new types (that were added to schema) in your Android app, after a schema-modification (in the project's backend folder) and a push, while using CLI.

If this isn't right, what is the right workflow to modify the schema and see the effects in the Android app?

(I am a beginner. TIA)

3

3 Answers

1
votes

amplify codegen is supposed to be like auth, api, etc.. you should add it to your amplify once and only once.

I believe it is this part of your step 3 that caused the issue

Generate and overwrite GraphQL statements? No

1
votes

There are two distinct products to be aware of:

  1. The AppSync SDK
  2. The Amplify Library's API Category

The first is a legacy wrapper around Apollo. The second is the current production library that the AWS team is supporting. Both talk to AppSync.

The link you cited redirects to the Amplify API documentation. The Amplify CLI was updated about a year ago, to generate code for the API category, not for the AppSync SDK.

If you want to use the AppSync SDK, I'd follow codeaddict's guideance, and also refer to the project's README.md.

If you want to use the Amplify Library, make note of the different instructions starting with Install Amplify Libraries.

0
votes

If you have a working AppSync API that you've tested on the AppSync console, you just want to use it in your Android App, you can run these commands at the root directory of your Android project:

  1. amplify init
  2. amplify add codegen --apiId xxxxxx
  3. amplify codegen