serverless-appsync/serverless-appsync-simulator

AppSync Simulator: TypeError: Cannot read property 'path' of undefined

appdatasoft opened this issue · 12 comments

Describe the bug
Getting error while setting up serverless-appysnc-emulator on windows
AppSync Simulator: TypeError: Cannot read property 'path' of undefined
To Reproduce
Steps to reproduce the behavior

Expected behavior
A clear and concise description of what you expected to happen.

TypeError: Cannot read property 'path' of undefined
at getAppSyncConfig (C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\serverless-appsync-simulator\lib\getAppSyncConfig.js:247:38)
at ServerlessAppSyncSimulator.initServer (C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\serverless-appsync-simulator\lib\index.js:85:50)
at Client. (C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\serverless-appsync-simulator\lib\index.js:147:14)
at Client.emit (events.js:315:20)
at Client.EventEmitter.emit (domain.js:482:12)
at BunserBuf. (C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\fb-watchman\index.js:90:14)
at BunserBuf.emit (events.js:315:20)
at BunserBuf.EventEmitter.emit (domain.js:482:12)
at BunserBuf.process (C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\bser\index.js:292:10)
at C:\Users\Administrator\Documents\appdatasoft\sumiventures\codemarket\parkyourselfbackend\node_modules\bser\index.js:247:12
at processTicksAndRejections (internal/process/task_queues.js:79:11)

 For debugging logs, run again after setting the "SLS_DEBUG=*" environment variable.

Get Support --------------------------------------------
Docs: docs.serverless.com
Bugs: github.com/serverless/serverless/issues
Issues: forum.serverless.com

Your Environment Information ---------------------------
Operating System: win32
Node Version: 12.18.2
Framework Version: 2.12.0
Plugin Version: 4.1.2
SDK Version: 2.3.2
Components Version: 3.4.1

Screenshots
If applicable, add screenshots to help explain your problem.
image

Additional context
Add any other context about the problem here.

Thank you @appdatasoft for raising this.

I see 2 different errors here
Cannot read property 'path' of undefined (title of hte ticket)
Cannot read defaultAuthenticationtype of undefined in the screenshot.

Could you please clarify the issue, show any output of the console, serverless.yml file, etc

It would help understand the problem better

thank you

Hi, I'm also facing Cannot read property 'defaultAuthenticationType' of undefined error. The error occurs a few seconds after I run sls offline start - no API request is necessary.

Update: I had serverless-plugin-typescript plugin and it caused this error. Now I've remove it and have another one: Error: UnauthorizedException: Missing authorization

@skix123 @appdatasoft Tryp to set the SLS_DEBUG env var to * (export SLS_DEBUG="*") and run sls offline start again.
Then check the logs, look for AppSync Simulator: and try to see why there is no defaultAuthenticationType

you should see something like

AppSync Simulator: {
  appSync: {
    name: '********',
    apiKey: '0123456789',
    defaultAuthenticationType: { authenticationType: 'API_KEY' },
    additionalAuthenticationProviders: []
  },
  schema: {
    path: 'appsync/schema.graphql',
    content: '.....'
  },
  resolvers: [
    ...
  ],
  dataSources: [
	...
  ],
  functions: []
}

@skix123 @appdatasoft Tryp to set the SLS_DEBUG env var to * (export SLS_DEBUG="*") and run sls offline start again.
Then check the logs, look for AppSync Simulator: and try to see why there is no defaultAuthenticationType

you should see something like

AppSync Simulator: {
  appSync: {
    name: '********',
    apiKey: '0123456789',
    defaultAuthenticationType: { authenticationType: 'API_KEY' },
    additionalAuthenticationProviders: []
  },
  schema: {
    path: 'appsync/schema.graphql',
    content: '.....'
  },
  resolvers: [
    ...
  ],
  dataSources: [
	...
  ],
  functions: []
}

@bboure

Here is the log after SSL_BEBUG IS SET:

serverless offline start
Serverless: To ensure safe major version upgrades ensure "frameworkVersion" setting in service configuration (recommended setup: "frameworkVersion: ^2.35.0")
Serverless: Invoke offline:start

AppSync Simulator: TypeError: Cannot read property 'path' of undefined
offline: Starting Offline: dev/us-east-2.
[offline] options: {
allowCache: false,
apiKey: 'd41d8abcdf00b204e9800998ecf1234',

@skix123 OK, if you are using typescript or any bundler, you have to update the path where the simulator looks for compiled code.

Example:

appsync-simulator:
    location: .build

OK, just realized your issue is about defaultAuthenticationType

can we please separate issues in 2 different tickets for clarity and tracking?

OK, just realized your issue is about defaultAuthenticationType

can we please separate issues in 2 different tickets for clarity and tracking?

@bboure looks like both the 2 issues are connected to each other.

Related issue/duplicate: #91

stale commented

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@appdatasoft Hi
Have the same issue
Have you figured it out?

trsrm commented

It is failing because the plugin is looking for a graphql.schema file inside the servicePath which is .build in case of TypeScript project. By default, this folder doesn't contain the schema file.

If you are using the serverless-plugin-typescript, then just update the package options with the following:

package:
    patterns:
        - 'schema.graphql'

Also, don't forget to update the `appsync-simulator' config:

appsync-simulator:
        location: '.build'
trsrm commented

@bboure Please, add this to the documentation to simplify TS integration.