aheissenberger / serverless-appsync-offline

Serverless AWS AppSync Offline Plugin - Allow to run AppSync locally for serverless framework
MIT License
90 stars 25 forks source link

ERROR: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object #28

Closed mhrisse closed 5 years ago

mhrisse commented 5 years ago

Hi!

First of all thanks for doing this project, well done.

We are setting up serverlesss-appsync-offline and only want to use lambdas as datasource.

I read the docs, but unfortunately I cannot find any simple example with serverless and lambda on the web to get us started. If you can help us out with this issue, we will happily contribute this back here. @aheissenberger

However we have run into the following problem:

terminal output:

$ sls appsync-offline start
Serverless: AppSync Standalone
Serverless: dynamoDB started: http://localhost:8000/
Serverless: ERROR: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object

with no working endpoint and the ERROR above.

or

$ sls offline
Serverless: Starting Offline: dev/us-west-2.

Serverless: Routes for graphql:
Serverless: (none)

Serverless: Offline listening on http://localhost:3000

with no route for graphql, respectively.

serverless.yml:

service: XXXXXXX-api

provider:
  name: aws
  runtime: nodejs8.10
  region: us-west-2
  stage: ${opt:stage, 'dev'} # Set the default stage used. Default is dev

plugins:
plugins:
  - serverless-dynamodb-local
  - serverless-appsync-plugin
  - serverless-appsync-offline
  - serverless-offline

functions:
  graphql:
    handler: handler.graphqlHandler

custom:
  appSync:
    name:  XXXXXXX-${self:provider.stage}-serverless
    region: ${self:provider.region}
    serviceRole: "${self:service.name}-AppSyncServiceRole"
    authenticationType: AMAZON_COGNITO_USER_POOLS
    userPoolConfig:
      defaultAction: ALLOW
      userPoolId: ********************
    mappingTemplatesLocation: # defaults to mapping-templates
    mappingTemplates:
      - type: Query
        dataSource: LambdaSource
        field: getPatients
        request: "query-getpatients-request.vtl"
        response: "common-response.vtl"
    dataSources:
      - type: AWS_LAMBDA
        name: LambdaSource
        description: "Lambda DataSource"
        config:
          functionName: graphql
          lambdaFunctionArn: { Fn::GetAtt: [GraphqlLambdaFunction, Arn] }
          serviceRoleArn: { Fn::GetAtt: [AppSyncLambdaServiceRole, Arn] }
  appsync-offline:
    port: 62222
    dynamodb:
      server:
        port: 8000

resources:
  - ${file(resources/appsync.yml)}

schema.graphql:

type Patient {
  id: ID!
  name: String!
}

type Query {
  getPatients: [Patient]
}

Any pointers very much appreciated!

aheissenberger commented 5 years ago

can you start with and post the result here: $ SLS_DEBUG=* sls appsync-offline start

mhrisse commented 5 years ago

Hi @aheissenberger !

Sure:

SLS_DEBUG=* sls appsync-offline start
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command dynamodb
Serverless: Load command dynamodb:migrate
Serverless: Load command dynamodb:seed
Serverless: Load command dynamodb:start
Serverless: Load command dynamodb:noStart
Serverless: Load command dynamodb:remove
Serverless: Load command dynamodb:install
Serverless: Load command delete-appsync
Serverless: Load command graphql-playground
Serverless: Load command deploy-appsync
Serverless: Load command update-appsync
Serverless: Load command appsync-offline
Serverless: Load command appsync-offline:start
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke appsync-offline:start
Serverless: AppSync Standalone
Serverless: dynamoDB started: http://localhost:8000/
Serverless: ERROR: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object

This is why I am calling out. I am stuck and do not even now where to start, as the message is too generic to google or even search in the code. Is there a way to expose a more detailed debug message?

aheissenberger commented 5 years ago

@mhrisse try SLS_DEBUG=* NODE_DEBUG=appsync-* sls appsync-offline start

try to user the newest version of the Serverless framework and node_modules

mhrisse commented 5 years ago

Hi @aheissenberger !

I am afraid it wont help, all same as before.

 SLS_DEBUG=* NODE_DEBUG=appsync-* sls appsync-offline start
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command create
Serverless: Load command install
Serverless: Load command package
Serverless: Load command deploy
Serverless: Load command deploy:function
Serverless: Load command deploy:list
Serverless: Load command deploy:list:functions
Serverless: Load command invoke
Serverless: Load command invoke:local
Serverless: Load command info
Serverless: Load command logs
Serverless: Load command metrics
Serverless: Load command print
Serverless: Load command remove
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command slstats
Serverless: Load command plugin
Serverless: Load command plugin
Serverless: Load command plugin:install
Serverless: Load command plugin
Serverless: Load command plugin:uninstall
Serverless: Load command plugin
Serverless: Load command plugin:list
Serverless: Load command plugin
Serverless: Load command plugin:search
Serverless: Load command config
Serverless: Load command config:credentials
Serverless: Load command rollback
Serverless: Load command rollback:function
Serverless: Load command delete-appsync
Serverless: Load command graphql-playground
Serverless: Load command deploy-appsync
Serverless: Load command update-appsync
Serverless: Load command appsync-offline
Serverless: Load command appsync-offline:start
Serverless: Load command offline
Serverless: Load command offline:start
Serverless: Invoke appsync-offline:start
Serverless: AppSync Standalone
Serverless: ERROR: TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received type object
barendb commented 5 years ago

@aheissenberger I've actually tracked down the cause of this

It looks like the multiple graphql files is not supported, but it is supported in the serverless-appsync-plugin

Our serverless config looks something like this...

appSync:
  schema:
    - "src/api/schema/file1.graphql"
    - "src/api/schema/file2.graphql"
    - "src/api/schema/schema.graphql"

When I run sls offline it gave me the following error

ERROR: Error: schema file: /Users/.../workspace/api/packages/sls-lambda/schema.graphql must exist

If I manually combine our graphql files and dump it in the default location everything works 100% ;)

aheissenberger commented 5 years ago

Oh great - I suggest to talk to the awesome guys who wrote the AppSync Emulator maybe they can add this feature - I am only maintaining this simple wrapper for Serverless integration.

barendb commented 5 years ago

Cool I've added a work around for the moment that we can live with

find ./src/api/schema -name "*.graphql" -o -name "schema.graphql" | xargs cat > ./graphql.schema

we'll just merge all the files before running sls offline and then ignore it in .gitignore 😂