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
87 stars 73 forks source link

Empty API Mock editor #1269

Open dan-hook opened 1 year ago

dan-hook commented 1 year ago

How did you install the Amplify CLI?

npm

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

v18.14.0

Amplify CLI Version

10.7.0

What operating system are you using?

Ubuntu 22.04 on WSL2 on Windows 10

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

Yes, the changes are extensive.

Describe the bug

I ran apt-get install java-11-amazon-corretto-jdk to install Java.

Running amplify mock api launches Amplify GraphiQL Explore on localhost:20002, but it's empty saying "No Schema Available". The CLI output is: vscode ➜ .../panel-api/project/amplify/backend (features/VCD-504-ecv-api ✗) $ amplify mock api GraphQL schema compiled successfully.

Edit your schema at /workspaces/gene-panel-api/project/amplify/backend/api/genepanelapi/schema.graphql or place .graphql files in a directory at /workspaces/gene-panel-api/project/amplify/backend/api/genepanelapi/schema Mock does not handle CloudFormation resource of type AWS::IAM::ManagedPolicy. Skipping processing resource AuthRolePolicy01. Mock does not handle CloudFormation resource of type AWS::IAM::ManagedPolicy. Skipping processing resource AuthRolePolicy02. Mock does not handle CloudFormation resource of type AWS::IAM::ManagedPolicy. Skipping processing resource AuthRolePolicy03. Data source of type RELATIONAL_DATABASE is not supported by local mocking. A NONE data source will be used. Data source of type HTTP is not supported by local mocking. A NONE data source will be used. Data source of type HTTP is not supported by local mocking. A NONE data source will be used. Data source of type HTTP is not supported by local mocking. A NONE data source will be used. Could not find ref for "RdsPanelDbName". Using unsubstituted value. Could not find ref for "RdsPanelDbName". Using unsubstituted value. Running GraphQL codegen ✔ Generated GraphQL operations successfully and saved at ../../src/graphql AppSync Mock endpoint is running at http://172.17.0.2:20002 Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Re-Trying with a new shard Mock DB deletion detected. Clearing the OpenSearch indices... Re-Trying with a new shard Re-Trying with a new shard Failed to start API Mocking. Running cleanup tasks. MockProcessFault: Failed to start API Mocking.. Reason: null at APITest.start (/snapshot/repo/build/node_modules/amplify-util-mock/lib/api/api.js:151:13) at runMicrotasks () at processTicksAndRejections (internal/process/task_queues.js:95:5) at async start (/snapshot/repo/build/node_modules/amplify-util-mock/lib/api/index.js:18:5) at async Object.run (/snapshot/repo/build/node_modules/amplify-util-mock/lib/commands/mock/api.js:21:5) at async Object.executeAmplifyCommand (/snapshot/repo/build/node_modules/amplify-util-mock/lib/amplify-plugin-index.js:47:3) at async executePluginModuleCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:142:5) at async executeCommand (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/execution-manager.js:40:9) at async Object.run (/snapshot/repo/build/node_modules/@aws-amplify/cli-internal/lib/index.js:117:5) { classification: 'FAULT', options: { message: 'Failed to start API Mocking.. Reason: null', link: 'https://docs.amplify.aws/cli/graphql/troubleshooting/' }, downstreamException: undefined, toObject: [Function (anonymous)], details: undefined, resolution: undefined, code: undefined, link: 'https://docs.amplify.aws/cli/graphql/troubleshooting/' }

Expected behavior

I expected to see the API in the explorer.

Reproduction steps

Run 'amplify mock api'

Project Identifier

9c19ea5526c1afd0a3e1987ea44f96af

Log output

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

Additional information

No response

Before submitting, please confirm:

raphipaffi commented 1 year ago

I have the same issue. Also using amplify 10.7.0. I am on a Mac M1. Looks very similar to this issue that already got resolved in 9.0.0 couple months ago: https://github.com/aws-amplify/amplify-cli/issues/10578

issakr commented 1 year ago

Same issue on amplify 10.7.1. I am also on a Mac M1.

josefaidt commented 1 year ago

Hey @dan-hook :wave: thanks for raising this! Was the amplify/mock-data directory deleted before mock finished initializing? Looking at this log item:

Mock DB deletion detected. Clearing the OpenSearch indices...

@raphipaffi @issakr on M1 macs you will need to install the 64-bit version of Java image

For example, this is the Java version I am running locally on my M1 mac

➜  java -version
openjdk version "18.0.1.1" 2022-04-22
OpenJDK Runtime Environment (build 18.0.1.1+2-6)
OpenJDK 64-Bit Server VM (build 18.0.1.1+2-6, mixed mode, sharing)
issakr commented 1 year ago

I already use openjdk `➜ java -version

openjdk version "17.0.4.1" 2022-08-12 OpenJDK Runtime Environment Temurin-17.0.4.1+1 (build 17.0.4.1+1) OpenJDK 64-Bit Server VM Temurin-17.0.4.1+1 (build 17.0.4.1+1, mixed mode)`

dan-hook commented 1 year ago

Hey @dan-hook 👋 thanks for raising this! Was the amplify/mock-data directory deleted before mock finished initializing? Looking at this log item:

Mock DB deletion detected. Clearing the OpenSearch indices...

I think that log item is spurious and may have even been caused by my computer going to sleep. There was 5-10 minutes between each "Re-Trying with a new shard". I stopped checking the Explorer after about six of them.

This is a complicated Amplify project and this is the first time I've tried running aws mock api on it. There were a number of issues such as VTL parsing errors that I needed to fix before I got this far, and I'm not surprised that there are still more issues. I'm not surprised it doesn't work, I just wish there was a better error message.

raphipaffi commented 1 year ago

I already have Java 64bit installed

➜ route-planner git:(master) ✗ java -version openjdk version "19.0.2" 2023-01-17 OpenJDK Runtime Environment Homebrew (build 19.0.2) OpenJDK 64-Bit Server VM Homebrew (build 19.0.2, mixed mode, sharing)

Let me know if there is anything else I can try.

josefaidt commented 1 year ago

Hey @raphipaffi @issakr given the M1 issue is different than what this issue is describing, would y'all mind filing a separate bug report to track your issue separately? We want to be sure this is addressed and documentation is updated if necessary. Do you experience the same issue using the official distribution from the OpenJDK downloads page?

@dan-hook

This is a complicated Amplify project and this is the first time I've tried running aws mock api on it.

Would you be open to sharing your schema.graphql? Do you have any overridden, slotted resolvers or custom resolvers that are causing the VTL parsing errors?

Upon further review of the error messaging I see the following error, are you using a Relational Database with your GraphQL API?

Data source of type RELATIONAL_DATABASE is not supported by local mocking. A NONE data source will be used.
NicholasAllen commented 1 year ago

I also started suffering this issue. I was trying on the 10.7.3 and 10.7.2 client builds. The following comment helped me resolve it for now: https://github.com/aws-amplify/amplify-cli/issues/10488#issuecomment-1434523750 - downgrade to 10.6.2 and it's working again.

raphipaffi commented 1 year ago

@NicholasAllen thank you so much for that tip! That downgrade also "fixed" it for me.

josefaidt commented 1 year ago

Hey folks I'm able to reproduce this issue using the Todo schema. Marking as a bug image

kmy90 commented 1 year ago

Hi, there is an ETA for the resolution of this bug?

dwamianm commented 1 year ago

@josefaidt. We are still experiencing this issue in 11.0.5. Any update on the fix?

FYI. Clearing mock files does not help. . I have @searchable annotations so I am unable to go back to 10.x.x

espenbye commented 1 year ago

We are experiencing the same issue on 11.0.5.

dwamianm commented 1 year ago

@josefaidt @phani-srikar This issue still exists in 11.1.0.

I would love to have this addressed if possible. I cannot downgrade to 10.6.2 because I am using OpenSearch mocking, which is only available in 11.x.x. I realize this may not seem like a priority but as a longtime Amplify. user it's a huge disadvantage to not have this feature in API mocking.

Any updates?

dwamianm commented 1 year ago

@josefaidt @phani-srikar ... any updates on this bug? It has really slowed development to not be able to use the tools to test locally. I am commenting here because It has been so long and I would really love to get this bug addressed so I can be on an updated amplify version. I am still stuck on 10.6.2 just to be able to get this to work :(

dwamianm commented 1 year ago

Checking for any updates on this bug. Still exists in 12.1.0

remotehpc commented 1 year ago

Hey folks I'm able to reproduce this issue using the Todo schema. Marking as a bug image

Hi Josef, are you able to resolve the bug or provide a walkaround? My team has been stuck here for too long, any help would be greatly appreciated!

Best regards!

aoi commented 1 year ago

@josefaidt Hi josefaidt.

Thank you for your response.

You have transfered this issue from amplify-cli repository to here. But the code has probrem is not in this repository. It is in amplify-cli repository. Please see my PR in amplify-cli repository.

amplify mock is very useful and important function for developers. A lot of developers are stuck in this bug for months. I would appreciate it if you could respond promptly.

Best regards,

pridapablo commented 1 year ago

I found that the error directly comes from adding Cognito User Pool auth to the api, no matter if API or IAM is also enabled. Working with amplify -v 12.0.0 since amplify mocks fail completely on m2 Mac using the latest version of the cli.

jmelendev commented 1 year ago

Im using -v 12.2.0 and seeing the same issues. I am seeing the following error in the console:

"Error: Error when generating OIDC token: Right-hand side of 'instanceof' is not an object"

Screen Shot 2023-07-26 at 9 35 59 PM

This was working fine earlier today, not sure what changed recently.

araymond11 commented 1 year ago

Any updates ? Same issue with Amplify CLI version 12.3.0.

kita3222 commented 11 months ago

I have confirmed that it also occurs in v12.4.0.

araymond11 commented 10 months ago

Still occurs in v12.7.0.

afnx commented 9 months ago

It's been months and still not able to see anything on Amplify GraphiQL Explorer.

There is this Uncaught (in promise) Error: Error when generating OIDC token: invalid 'instanceof' operand g error that everybody mentioned on my browser console.

Also, when I try to execute a query, I always get the unauthorized error:

{
  "errors": [
    {
      "errorType": "UnauthorizedException",
      "message": "UnauthorizedException: Missing authorization"
    }
  ]
}
zakton5 commented 9 months ago

As mentioned by others developing and testing locally is very important and without it the development process is far slower. @josefaidt Are there any updates?

kmy90 commented 8 months ago

Hi everyone, this issue was opened almost 1 year ago. It is NOT a MINOR bug. There are teams around the world that are not able to use the latest version of Amplify just because of this problem. Could you help us, @josefaidt, @alharris-at ?

rafadpedrosa commented 7 months ago

I would like to share my experience, maybe will help someone.

Yes, I'm having the same issue as everyone. But, given that I use nvm to control my node versions, I "manage" to deal with this problem installing different amplify-cli version on different node version as mentioned here.

nvm use 20 
npm install npm install -g @aws-amplify

nvm use 18 
npm install -g @aws-amplify/cli@10.6.2 // working version

Also, I do agree with @kmy90. It should not be treated as a minor thing.

afnx commented 7 months ago

Hey folks, this is a serious issue here impacting everyone and disrupting the development process. Using workarounds, like downgrading the Amplify version, isn't the most convenient solution. Personally, I struggled with testing my projects locally using the explorer, and it really bothered me that such an important issue had been left unattended for a year.

I fixed it by creating a PR (https://github.com/aws-amplify/amplify-cli/pull/13555). Can you please support it? We need the Amplify team to review and approve the fix. Thanks!

zepelega commented 5 months ago

Still occurs in v12.10.1.

afnx commented 4 months ago

Fixed in version 12.11.0