Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"No AppSync API configured" when running "amplify codegen models" #5069

Closed
RandomEngy opened this issue Aug 12, 2020 · 9 comments
Closed

"No AppSync API configured" when running "amplify codegen models" #5069

RandomEngy opened this issue Aug 12, 2020 · 9 comments
Labels
question General question

Comments

@RandomEngy
Copy link

Describe the bug
Model generation doesn't work. It claims that no API is configured, but all indications are that it does have an API.

Amplify CLI Version
4.27.1

To Reproduce
Added an Api from an existing API:
amplify add codegen --apiId df4pcs54qfc7tjy4mzokjtco5y

Ran:
amplify codegen models

Got No AppSync API configured. Please add an API

Ran amplify status:

C:\git\FocalistKotlin>amplify status

Current Environment: prod

| Category | Resource name          | Operation | Provider plugin   |
| -------- | ---------------------- | --------- | ----------------- |
| Api      | Focalist               | No Change |                   |
| Auth     | focalistkotlinxxxxxxxx | No Change | awscloudformation |

In amplifyconfiguration.json:

    "api": {
        "plugins": {
            "awsAPIPlugin": {
                "Focalist": {
                    "endpointType": "GraphQL",
                    "endpoint": "https://xxxxxxxxxxxxxxxxxx.appsync-api.us-east-2.amazonaws.com/graphql",
                    "region": "us-east-2",
                    "authorizationType": "AMAZON_COGNITO_USER_POOLS"
                }
            }
        }
    },

I also see all properly populated .graphql files in app\src\main\graphql\com\amazonaws\amplify\generated\graphql

Expected behavior
The model generation works.

Desktop (please complete the following information):

  • OS: Windows
  • Node Version: 12.16.3
@SwaySway SwaySway added code-gen pending-triage Issue is pending triage labels Aug 12, 2020
@RandomEngy
Copy link
Author

I'm digging into the code and I see that it is looking for resources with providerPlugin === "awscloudformation" . Mine does not have that provider plugin set. It looks like it was generated that way when I added the API.

@SwaySway
Copy link
Contributor

When running amplify add codegen --apiId ... this is generating types for your appsync schema. The schema that is downloaded is an introspection schema which does not have @model directive attached. As using amplify codegen models is used with a DataStore enabled Amplify project.

@SwaySway SwaySway added question General question pending-close-response-required and removed pending-triage Issue is pending triage labels Aug 12, 2020
@RandomEngy
Copy link
Author

RandomEngy commented Aug 12, 2020

I had this working earlier. And the AppSync documentation says this can generate types:

image

What command is supposed to generate types in this case?

It links off to the general "amplify" guide for Android, and the only thing I can find in there mentions "amplify codegen" or "amplify codegen models" which USED to generate working model classes but no longer seem to.

@SwaySway
Copy link
Contributor

If you built your AppSync API outside of Amplify there is portion of the docs here which go over this:
https://docs.amplify.aws/sdk/api/graphql/q/platform/android#configuration

@RandomEngy
Copy link
Author

RandomEngy commented Aug 12, 2020

Ahh okay. I think I finally puzzled it out. The actual code generation in this case is done with the gradle plugin com.amazonaws.appsync. I was missing that, so the code was not being generated. I was thrown off by all of the amplify cli "codegen" stuff. I had com.amplifyframework.amplifytools but that wasn't the correct plugin.

Thanks for the help.

@RandomEngy
Copy link
Author

And figuring things out even more: There are two types of class generation happening!

  1. Classes generated by the com.amazonaws.appsync gradle plugin. They work with the classic aws-android-sdk-appsync library with AWSAppSyncClient.query() and AWSAppSyncClient.mutate(). They can work from graphql that's downloaded from amplify add codegen --apiId ...
  2. Classes generated by amplify codegen models . These work with Amplify.API.mutate() and Amplify.API.query() . They require @model type annotations and do not support an API added from amplify add codegen --apiId ... .

The weird part is that the AppSync console prompts you to add via --apiId then links you off to https://docs.aws.amazon.com/appsync/latest/devguide/building-a-client-app.html . You then follow the Android Documentation link and it brings you to https://docs.amplify.aws/lib/graphqlapi/getting-started/q/platform/android . That talks about the "amplify" way of doing things, which doesn't work!

@Taha-Mohsin
Copy link

Hey, I'm facing the same issue.
Did you manage to solve this?

@RandomEngy
Copy link
Author

Yes, as mentioned in my last update. If you add via API ID then you need to use the old AWSAppSyncClient and Gradle plugin. It does not work via the amplify API.

@github-actions
Copy link

This issue has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question General question
Projects
None yet
Development

No branches or pull requests

3 participants