Amplify-cli: Local Mocking API doesn't honour custom resolver response template names

Created on 23 Sep 2019  路  4Comments  路  Source: aws-amplify/amplify-cli

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.

  1. Create a file in <api>/resolvers/Mutation.createBodyBlock.req.vtl.
  2. Create a file in <api>/resolvers/passthrough.res.vtl
  3. Create a CloudFormation template entry in stacks/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"
              }
            }
          ]
        }
      }
    }
  1. Start local mocking: amplify mock api
  2. See error:
Failed 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.

bug mock

Most helpful comment

All 4 comments

actually it does not even take the name for request template. I think it is taking the template names from fieldname parameter.

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

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mwarger picture mwarger  路  3Comments

kstro21 picture kstro21  路  3Comments

MageMasher picture MageMasher  路  3Comments

jexh picture jexh  路  3Comments

adriatikgashi picture adriatikgashi  路  3Comments