Describe the bug
When custom resolver response templates have been defined with a non-standard name, even though those names are defined in the resolver CloudFormation template, these names are not used. Instead the local mocking code looks for a response template with the same name as the request template, but with .res.vtl extension.
Note that the same setup works fine non-locally after an amplify push
To Reproduce
Create a custom resolver for a mutation eg. Mutation.createBodyBlock.
<api>/resolvers/Mutation.createBodyBlock.req.vtl.<api>/resolvers/passthrough.res.vtlstacks/CustomResources.json which specifies the above two locations for the Request and Response portions of the resolver: "MutationCreateBodyBlockResolver": {
"Type": "AWS::AppSync::Resolver",
"Properties": {
"ApiId": {
"Ref": "AppSyncApiId"
},
"DataSourceName": "BasicBlockTable",
"TypeName": "Mutation",
"FieldName": "createBodyBlock",
"RequestMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/Mutation.createBodyBlock.req.vtl",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
}
}
]
},
"ResponseMappingTemplateS3Location": {
"Fn::Sub": [
"s3://${S3DeploymentBucket}/${S3DeploymentRootKey}/resolvers/passthrough.res.vtl",
{
"S3DeploymentBucket": {
"Ref": "S3DeploymentBucket"
},
"S3DeploymentRootKey": {
"Ref": "S3DeploymentRootKey"
}
}
]
}
}
}
amplify mock apiFailed to start API Mock endpoint Error: Invalid config for UNIT_RESOLVER {"dataSourceName":"BasicBlockTable","typeName":"Mutation","fieldName":"createBodyBlock","requestMappingTemplateLocation":"resolvers/Mutation.createBodyBlock.req.vtl","responseMappingTemplateLocation":"resolvers/Mutation.createBodyBlock.res.vtl","kind":"UNIT"}
Missing mapping template resolvers/Mutation.createBodyBlock.res.vtl
Expected behavior
It should use the name provided in the stack for the response template, and not assume that it's the same as the request template with a different suffix.
actually it does not even take the name for request template. I think it is taking the template names from fieldname parameter.
This is fixed by https://github.com/aws-amplify/amplify-cli/pull/2355
The problem still exists.
Failed to start API Mock endpoint Error: Invalid config for UNIT_RESOLVER {"dataSourceName":"TodoTable","typeName":"Query","fieldName":"scanTodos","requestMappingTemplateLocation":"resolvers/Query.scanTodos.req.vtl","responseMappingTemplateLocation":"resolvers/Query.scanTodos.res.vtl","kind":"UNIT"}
Missing mapping template resolvers/Query.scanTodos.req.vtl
running npm install -g @aws-amplify/cli to upgrade to the newest version fixed this for me. i am on windows and this patch fixed my issue: https://github.com/aws-amplify/amplify-cli/commit/87c4ad59a701995220946ad35f1491f0d4b57325
thank you team
Most helpful comment
This is fixed by https://github.com/aws-amplify/amplify-cli/pull/2355