Can't start offline: not finding mappingTemplates?
Closed this issue · 6 comments
Thanks for creating this plugin.
When I'm using serverless-appsync-simulator 0.3.4 I get an error when running offline:
AppSync Simulator: TypeError: (appSyncConfig.mappingTemplates || []).flat is not a function
I also tried making file references since I saw an issue where file mapping support was added.
Here is the relevant part of my serverless config:
plugins:
- serverless-pseudo-parameters
- serverless-appsync-simulator
- serverless-appsync-plugin
- serverless-offline
functions:
auth:
handler: functions/auth/handler.fetch
cors: true
getPost:
handler: functions/getPost/handler.fetch
cors: true
custom:
serverless-offline:
port: 3001
region: ${opt:region, self:provider.region}
appSync:
mappingTemplates:
- type: Query
dataSource: LambdaSource
field: getPost
# request: "query-getpatients-request.vtl"
# response: "common-response.vtl"
dataSources:
- type: AWS_LAMBDA
name: LambdaSource
description: "Lambda DataSource"
config:
functionName: graphql
lambdaFunctionArn: ${self:provider.role}
serviceRoleArn: ${self:provider.role}
@vance Are you using the serverless components plugin for Appsync?
This plugin is not meant to work with that.
I still see that your file looks more like a config file for the "traditional" serverless plugin, so maybe it's a mistake?
If you are using the plugin, then could you try to debug and see what comes in appSyncConfig.mappingTemplates
?
I am using the plugins. Will get debug shortly.
plugins:
- serverless-pseudo-parameters
- serverless-appsync-simulator
- serverless-appsync-plugin
- serverless-offline
I can't find in the serverless -help
how to get verbose stack traces. I tried just copying the config from the plugin readme, but get the same error.
custom:
appSync:
mappingTemplates:
- type: Query
field: testPipelineQuery
request: './mapping-templates/before.vtl' # the pipeline's "before" mapping template, defaults to {type}.{field).request.vtl
response: './mapping-templates/after.vtl' # the pipeline's "after" mapping template, defaults to {type}.{field}.response.vtl
kind: PIPELINE
functions:
- authorizeFunction
- fetchDataFunction
functionConfigurations:
- dataSource: graphqlLambda
name: 'authorizeFunction'
request: './mapping-templates/authorize-request.vtl' # defaults to {name}.request.vtl
response: './mapping-templates/common-response.vtl' # defaults to {name}.response.vtl
- dataSource: dataTable
name: 'fetchDataFunction'
request: './mapping-templates/fetchData.vtl' # defaults to {name}.request.vtl
response: './mapping-templates/common-response.vtl' # defaults to {name}.response.vtl
I get around the error now. It was because I'm an idiot and copy pasta'd my package.json from another project that had this in the buried deep in the local start script:
serverless offline start -s local
that runs it in backward compatibility mode. Will close and re-open if there's still an issue. thanks!
I'm running into the same issue. I tried running serverless offline without the start command which would run it in backward compatibility mode as @vance said but when running serverless offline like that the plugin doesn't seem to start. Deploying serverless also works.
For anyone else that might run into this my issue that I was using an older version of node that didn't support the flat method on my personal computer.