Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to generate classes for GraphQL API (AWS AppSync) using Amplify

I have a GraphQL API on AWS AppSync pushed by another person and want to connect to it and fetch data in my Android application. According to AWS documentation, to integrate the API with my app I should execute 3 following commands:

  npm install -g @aws-amplify/cli
  amplify init
  amplify add codegen --apiId xxxxxx

After that, I need to generate Java classes based on the graphql schema. I execute amplify codegen models but get an error "No AppSync API configured. Please add an API". If execute amplify add api, I get "You already have an AppSync API in your project. Use the "amplify update api" command to update your existing AppSync API."

Why can't I generate classes?

aws-amplify/cli v4.18.1

like image 367
Anton Polkanov Avatar asked Nov 05 '25 05:11

Anton Polkanov


1 Answers

You should use Amplify Mobile SDK instead of Amplify Libraries to generate classes for an API created in the AWS Console. It really confuses that you have to use different approaches for generation. In addition, on AWS in the API overview there is a wrong link which refers you not to the mobile sdk, but to the libraries.

Generation process for API created in the console is described in Code Generation / AppSync APIs Created in the Console https://docs.amplify.aws/sdk/api/graphql/q/platform/android#code-generation

enter image description here

like image 137
Anton Polkanov Avatar answered Nov 07 '25 07:11

Anton Polkanov



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!