aws-amplify / amplify-category-api

The AWS Amplify CLI is a toolchain for simplifying serverless web and mobile development. This plugin provides functionality for the API category, allowing for the creation and management of GraphQL and REST based backends for your amplify project.
https://docs.amplify.aws/
Apache License 2.0
89 stars 77 forks source link

amplify push does not work when existing GraphQL API is added #2140

Open lukasulbing opened 10 months ago

lukasulbing commented 10 months ago

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

20.9.0

Amplify CLI Version

12.10.0

What operating system are you using?

Mac

Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.

I have added an existing GraphQL API with amplify add codegen --apiId xxxxxxxx. No other "manual" changes were made.

Describe the bug

I want to use Amplify in my JS web app to utilize authentication with Cognito and query data from DynamoDB tables via a GraphQL API (AppSync).

amplify status returns the following: Screenshot 2023-12-18 at 13 31 08

As you can see, I have already added the authentication with amplify add auth.

I have an existing GraphQL API in AppSync and I want to add it to my Amplify configuration. I use amplify add codegen --apiId xxxxxxxx to generate the necessary code and the API gets added to my local backend as follows. Screenshot 2023-12-18 at 13 39 00

So far so good... but when I run amplify push to also transfer this configuration to my remote backend in Amplify, basically nothing happens. Except that the operation changes from No Change to Create: Screenshot 2023-12-18 at 13 43 20

Then I tried to force push this with amplify push --force to see what happens, but it didn't go any further than this: Screenshot 2023-12-18 at 16 52 42

After 30 minutes I stopped this with CMD + C, but I found my GraphQL API in Amplify Studio: Screenshot 2023-12-18 at 16 56 57

Even though the GraphQL API seems deployed I cannot access it within my backend.

Expected behavior

Whenever I add a GraphQL API to my project with amplify codegen add ... it also shows up when I run amplify status. So when I push these changes I expect it to be correctly pushed to the amplify backend.

Reproduction steps

  1. Add Authentication - amplify add auth
  2. Add existing GraphQL API - amplify add codegen --apiId xxxxxxxx
  3. Push local backend - amplify push

Project Identifier

Project Identifier: 79f15d992b5c3e5a87865affa94191ba

Log output

``` # Put your logs below this line ```

Additional information

No response

Before submitting, please confirm:

AnilMaktala commented 10 months ago

Hey @lukasulbing, Thanks for raising this. I'm unable to reproduce the problem; it appears to be related to a potential network issue. Could you confirm if your app and API are in the same region?

image
lukasulbing commented 10 months ago

Hey @AnilMaktala, thanks for your reply. Yes, my Amplify project as well as my AppSync API are in the same region (eu-west-1). The following is my amplifyconfiguration.json:

{
  "aws_project_region": "eu-west-1",
  "aws_cognito_region": "eu-west-1",
  "aws_user_pools_id": "eu-west-1_xxxxxx",
  "aws_user_pools_web_client_id": "xxxxxxxxx",
  "oauth": {
    "domain": "xxxxxxx.auth.eu-west-1.amazoncognito.com"
  },
  "aws_cognito_username_attributes": [
    "EMAIL"
  ],
  "aws_cognito_social_providers": [],
  "aws_cognito_signup_attributes": [
    "EMAIL"
  ],
  "aws_cognito_mfa_configuration": "ON",
  "aws_cognito_mfa_types": [
    "TOTP"
  ],
  "aws_cognito_password_protection_settings": {
    "passwordPolicyMinLength": 8,
    "passwordPolicyCharacters": [
      "REQUIRES_LOWERCASE",
      "REQUIRES_UPPERCASE",
      "REQUIRES_NUMBERS",
      "REQUIRES_SYMBOLS"
    ]
  },
  "aws_cognito_verification_mechanisms": [
    "EMAIL"
  ],
  "aws_appsync_graphqlEndpoint": "https:/xxxxxxxxx.appsync-api.eu-west-1.amazonaws.com/graphql",
  "aws_appsync_region": "eu-west-1",
  "aws_appsync_authenticationType": "API_KEY",
  "aws_appsync_apiKey": "da2-xxxxxxxx"
}
lukasulbing commented 10 months ago

Whenever I try to push this configuration it says No AppSync API configured. Please add an API at the end like in the screenshot above.

lukasulbing commented 10 months ago

By the way, I've found a similar issue here, but it has been closed without providing a solution: https://github.com/aws-amplify/amplify-cli/issues/8394

dpilch commented 10 months ago

I also was not able to reproduce the issue. Did you try removing the API like suggested in issue you linked?

lukasulbing commented 10 months ago

Yes, I removed the API with amplify api remove and linked it again with amplify add codegen --apiId xxxxxx but this didn't help.

One of the staff members over on the Amplify discord server suggested to add the output of amplify push --debug to this issue.

Screenshot 2023-12-19 at 18 20 13

I see some error messages on here, could this lead to a problem?

lukasulbing commented 10 months ago

Also, I am willing to set up a completely fresh amplify app to see if it's related to my local machine. In that case, it would be kind of you to tell me the commands you when you tried to reproduce the issue.

AnilMaktala commented 10 months ago

Hey @lukasulbing, Thank you for providing the additional information. I've performed the following steps to replicate the problem:

  1. amplify init
  2. amplify add auth
  3. amplify add codegen --apiId xxxxxxxx
  4. amplify push

Please let me know if I am missing anything in my approach here.

lukasulbing commented 10 months ago

Alright, I have created a new Amplify app and js project to test this. I've even left out adding the authentication.

I've run the same commands you provided (except add auth) and the only thing I did additionally was to enable Amplify Studio and pull this backend into the project (I'm not sure if this is even necessary, because the backend is empty at this point).

Then I added the GraphQL API from AppSync and pushed everything. The result was the same, nothing happened in Amplify Studio under the GraphQL tab...

This basically summarizes the steps I've taken to reproduce the issue:

  1. create new Next.js project
  2. install dependencies
  3. amplify init
  4. enable Amplify Studio
  5. amplify pull --appId xxxxxx --envName dev
  6. amplify add codegen --apiId xxxxxxxx
  7. amplify push

I can't tell if it's related to my machine unfortunately. Do you have any more ideas what I could do to find the root cause?

lukasulbing commented 10 months ago

Hi, I've also tested this on a computer of my colleague (also Mac). I followed the exact same steps as mentioned above and it resulted in the same problem. After amplify push it says No AppSync API configured. Please add an API and no API is showing in Amplify Studio.

ykethan commented 10 months ago

@AnilMaktala @dpilch I think i have a repro for this issue, was testing multiple things.

  1. on the AWS AppSync console, created a new API in eu-west-1. New API -> API type(GraphQL APIs, Design from scratch) Specify API details -> added some name(testApi) Specify GraphQL resources -> Create type backed by a DynamoDB table now. Model name(test) -> created some fields -> Resolver runtime(default: AppSync JavaScript (APPSYNC_JS)) -> Configure model table(Todo) -> create API
  2. amplify init (didnt create a frontend app in my test and forget my profile was for us-east-1)
    ✖ Getting API details
    AppSync API was not found in region us-east-1
    ? Do you want to choose a different region Yes
    ? Choose AWS Region EU (Ireland)
    ⠏ Getting API detailsSuccessfully added API tesimp to your Amplify project
    ✔ Getting API details
    ? Choose the code generation language target javascript
    ? Enter the file name pattern of graphql queries, mutations and subscriptions src/graphql/**/*.js
    ? Do you want to generate/update all possible GraphQL operations - queries, mutations and subscriptions Yes
    ? Enter maximum statement depth [increase from default if your schema is deeply nested] 2
    ✔ Downloaded the schema
    ✔ Generated GraphQL operations successfully and saved at src/graphql 
  3. amplify add codegen --apiId <apiId>
  4. amplify push
  5. amplify status shows the API is in create

    
    
    Current Environment: dev

┌──────────┬───────────────┬───────────┬─────────────────┐ │ Category │ Resource name │ Operation │ Provider plugin │ ├──────────┼───────────────┼───────────┼─────────────────┤ │ Api │ tesimp │ Create │ │ └──────────┴───────────────┴───────────┴─────────────────┘



@lukasulbing is this config of the AppSync API similar to the reproduction steps above?
lukasulbing commented 10 months ago

@ykethan Yes, this is also what I've done. There are some differences in GraphQL API linking, but I don't think they can have an impact.

I'll let you know about them just in case: The code generation language target in my project is typescript and I've changed the file name pattern to app/graphql/**/*ts. Also, I see the option to change the location of API.ts which I've updated to app/API.ts.

Other than that, this is exactly what I'm seeing and when I try to push it, nothing changes in Amplify Studio under the GraphQL API tab.

AnilMaktala commented 9 months ago

Hey @lukasulbing, Can you verify the region from which you're attempting to import? Additionally, consider adding the -region in the import command as suggested here to check if it resolves your issue..

lukasulbing commented 9 months ago

Hey @AnilMaktala, I have been using the command from the Webinterface of AppSync npx @aws-amplify/cli codegen add --apiId xxxxxxxxxx --region eu-west-1 to import the GraphQL API.