Amplify-cli: [mock] Custom Resources or custom resolvers don't appear to be honored

Created on 9 Aug 2019  路  6Comments  路  Source: aws-amplify/amplify-cli

Describe the bug
When using mock, it doesn't appear that custom resolvers in the resolvers directory are "seen" by the tool.

Receive an error (screenshot below):

GraphQL schema compiled successfully.

Edit your schema at /Users/mwarger/dev/projects/conference-app-in-a-box/amplify/backend/api/rnconfinabox/schema.graphql or place .graphql files in a directory at /Users/mwarger/dev/projects/conference-app-in-a-box/amplify/backend/api/rnconfinabox/schema
Creating table TalkTable locally
Creating table CommentTable locally
Creating table ReportTable locally
Failed to start API Mock endpoint Error: Invalid config for UNIT_RESOLVER {"dataSourceName":"CommentTable","typeName":"Query","fieldName":"listCommentsByTalkId","requestMappingTemplateLocation":"resolvers/Query.listCommentsByTalkId.req.vtl","responseMappingTemplateLocation":"resolvers/Query.listCommentsByTalkId.res.vtl","kind":"UNIT"}
Missing mapping template resolvers/Query.listCommentsByTalkId.req.vtl

To Reproduce
Steps to reproduce the behavior:

  1. Clone https://github.com/dabit3/conference-app-in-a-box
  2. Follow instructions, including running amplify init
  3. Run amplify mock
  4. The resolvers are all put into the resolvers folder, but an error says that the two that are already there (the custom ones) cannot be found. The paths match, though, so something isn't seeing this correctly.

Expected behavior
It should work.

Screenshots
Before mock:
image

After mock:
image

Error:
image

Desktop (please complete the following information):

  • OS: [e.g. iOS] Mac
bug mock

Most helpful comment

Yes. I could reproduce this. conference-app-in-a-box has a schema has custom query

type Query {
  listCommentsByTalkId(talkId: ID!): ModelCommentConnection
}

For this custom query, it uses CustomResources.json stack to create the resolver and inserts the required mapping template in resolvers folder. Mock server did not look at either the custom stack or did not honor existing resolver which were not created by GraphQL transformer

I am working on a fix for this.

All 6 comments

Hey, I just tested this and it works, but in a brand new project.

I'm wondering if there is some sort of conflict in a project that has already been deployed. Is this in a project with a live API, or is this completely local?

This happens if you have a custom resource stack. Mock serve is not parsing the custom stack and is missing the resource created by it

Hey, I just tested this and it works, but in a brand new project.

I'm wondering if there is some sort of conflict in a project that has already been deployed. Is this in a project with a live API, or is this completely local?

This was a new project. I will change accounts to make sure I don't have anything existing.

This happens if you have a custom resource stack. Mock serve is not parsing the custom stack and is missing the resource created by it

@yuth are you saying you were able to reproduce this?

Yes. I could reproduce this. conference-app-in-a-box has a schema has custom query

type Query {
  listCommentsByTalkId(talkId: ID!): ModelCommentConnection
}

For this custom query, it uses CustomResources.json stack to create the resolver and inserts the required mapping template in resolvers folder. Mock server did not look at either the custom stack or did not honor existing resolver which were not created by GraphQL transformer

I am working on a fix for this.

I think I misunderstood this initially. I was also now able to reproduce after cloning the project. Previously I was unable to reproduce because I was in a new project.

Steps to reproduce:

  1. Clone project at https://github.com/dabit3/conference-app-in-a-box
~ git clone https://github.com/dabit3/conference-app-in-a-box.git
  1. Initialize amplify project
amplify init
  1. Mock API
amplify mock api
Was this page helpful?
0 / 5 - 0 ratings