amplify-category-api icon indicating copy to clipboard operation
amplify-category-api copied to clipboard

Empty API Mock editor

Open dan-hook opened this issue 2 years ago • 30 comments

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:

  • [X] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.
  • [X] I have removed any sensitive information from my code snippets and submission.

dan-hook avatar Feb 04 '23 16:02 dan-hook

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

raphipaffi avatar Feb 05 '23 22:02 raphipaffi

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

issakr avatar Feb 06 '23 17:02 issakr

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)

josefaidt avatar Feb 06 '23 17:02 josefaidt

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)`

issakr avatar Feb 06 '23 18:02 issakr

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.

dan-hook avatar Feb 06 '23 21:02 dan-hook

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.

raphipaffi avatar Feb 10 '23 19:02 raphipaffi

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.

josefaidt avatar Feb 14 '23 16:02 josefaidt

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.

NicholasAllen avatar Feb 17 '23 14:02 NicholasAllen

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

raphipaffi avatar Feb 17 '23 22:02 raphipaffi

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

josefaidt avatar Feb 18 '23 00:02 josefaidt

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

kmy90 avatar Apr 04 '23 15:04 kmy90

@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

dwamianm avatar Apr 17 '23 14:04 dwamianm

We are experiencing the same issue on 11.0.5.

espenbye avatar Apr 24 '23 12:04 espenbye

@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 avatar Apr 27 '23 20:04 dwamianm

@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 avatar Jun 05 '23 14:06 dwamianm

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

dwamianm avatar Jun 15 '23 17:06 dwamianm

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!

remotehpc avatar Jul 04 '23 22:07 remotehpc

@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,

aoi avatar Jul 06 '23 00:07 aoi

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.

pridapablo avatar Jul 27 '23 01:07 pridapablo

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.

jmelendev avatar Jul 27 '23 01:07 jmelendev

Any updates ? Same issue with Amplify CLI version 12.3.0.

araymond11 avatar Aug 27 '23 20:08 araymond11

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

kita3222 avatar Sep 27 '23 04:09 kita3222

Still occurs in v12.7.0.

araymond11 avatar Oct 18 '23 22:10 araymond11

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"
    }
  ]
}

afnx avatar Nov 20 '23 07:11 afnx

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?

zakton5 avatar Nov 21 '23 19:11 zakton5

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 ?

kmy90 avatar Dec 18 '23 21:12 kmy90

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/[email protected] // working version

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

rafadpedrosa avatar Jan 21 '24 14:01 rafadpedrosa

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!

afnx avatar Jan 31 '24 09:01 afnx

Still occurs in v12.10.1.

zepelega avatar Mar 17 '24 22:03 zepelega

Fixed in version 12.11.0

afnx avatar Apr 25 '24 01:04 afnx