amplify-cli icon indicating copy to clipboard operation
amplify-cli copied to clipboard

amplify mock api: TypeError: Cannot read property 'props' of undefined

Open NeillGiraldo opened this issue 7 years ago • 7 comments

Note: If your issue/bug is regarding the AWS Amplify Console service, please log it in the Amplify Console GitHub Issue Tracker

Describe the bug I have GraphQL API that was created outside of Amplify. I would like to integrate the local testing option that amplify provides into our development project. However I got this error on the browser TypeError: Cannot read property 'props' of undefined when I run amplify mock api

Amplify CLI Version 3.17.0

To Reproduce On an empty folder I run

  • amplify init
  • (configure the setting of the project) - Keep in mind here I am not having any react/angular or any other app. just amplify.
  • amplify add api
    • ? Please select from one of the below mentioned services: GraphQL
    • ? Provide API name: appsynctest
    • ? Choose the default authorization type for the API IAM
    • ? Do you want to configure advanced settings for the GraphQL API No
    • ? Do you have an annotated GraphQL schema? Yes
    • ? Provide your schema file path: schema.graphql
  • amplify mock api
    • ? Choose the code generation language target javascript
    • ? Enter the file name pattern of graphql queries, mutations and subscriptions sr c/graphql/**/*.js
    • ? Do you want to generate/update all possible GraphQL operations - queries, muta tions and subscriptions Yes
    • ? Enter maximum statement depth [increase from default if your schema is deeply nested] 2 ✔ Generated GraphQL operations successfully and saved at src/graphql AppSync Mock endpoint is running at http://xx.xx.xx.xxx:20002

However when I go to the browser, it tries to load the local testing feature but then immediately it throws the following error

Cannot read property 'props' of undefined on ToolbarSelect.js

Expected behavior I would like to be able to access the UI for testing my Graphql API locally,

Screenshots Screenshot 2019-11-14 at 14 50 09

Desktop (please complete the following information):

  • OS: Mac
  • Node Version: v10.15.3

Additional context

NeillGiraldo avatar Nov 14 '19 13:11 NeillGiraldo

@NeillGiraldo This does look like a React error but it's hard to find out where it's originating from. Likely not a CLI error.

ammarkarachi avatar Nov 21 '19 22:11 ammarkarachi

Hi @ammarkarachi, Thanks for your answer. Yes, it is a bit hard but I think the problem might be in amplify-graphiql-explorer. I have tried to do a local testing using amplify-appsync-simulator & amplify-graphiql-explorer with my own Configuration. I have found that if you use

  const AppSyncConfig = {
       name: 'AppSync',
       defaultAuthenticationType: { authenticationType: 
            simulator.AmplifyAppSyncSimulatorAuthenticationType.AWS_IAM},
       additionalAuthenticationProviders: [],
  }

const configuration = {
  schema: {
    content: schema
  },
  resolvers,
  mappingTemplates,
  functions: [functionsSimulation],
  dataSources: [dataSourceDDB],
  appSync: AppSyncConfig,
};

appSyncSimulator.init(configuration);
appSyncSimulator.start();

you get the error but If you change the AuthenticationType to

const AppSyncConfig = {
  name: 'AppSync',
  defaultAuthenticationType: { authenticationType: simulator.AmplifyAppSyncSimulatorAuthenticationType.apiKey},
  additionalAuthenticationProviders: [],
  apiKey: 'da2-fakeApiId123456',
}

The problem disappears.

The authenticationTypes used in graphiQL might not match all the authentication modes , IAM is missing.

The error is being thrown here at some render because the select component cannot find a selected child. Hope this helps.

NeillGiraldo avatar Nov 22 '19 09:11 NeillGiraldo

@NeillGiraldo We don't support IAM for mock. The reason is the resolution for IAM happens in the cloud and we can't simulate that on local for mock. Let me know if you have any other questions.

ammarkarachi avatar Dec 13 '19 19:12 ammarkarachi

Im having this same issue where its not rendering props when I type in amplify mock

nikhilbatta avatar Feb 04 '20 23:02 nikhilbatta

I believe this issue has been fixed with PR #3285. Please let us know if you're still seeing this issue.

kaustavghosh06 avatar Feb 17 '20 22:02 kaustavghosh06

This PR #3476 also helps to solve the problem.

NeillGiraldo avatar Mar 02 '20 13:03 NeillGiraldo

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[bot] avatar May 26 '21 15:05 github-actions[bot]