question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

All the VTL resolvers cannot be updated by modifying `schema.graphql` after Mocking.

See original GitHub issue

Before opening, please confirm:

  • I have installed the latest version of the Amplify CLI (see above), and confirmed that the issue still persists.
  • I have searched for duplicate or closed issues.
  • I have read the guide for submitting bug reports.
  • I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

How did you install the Amplify CLI?

npm

If applicable, what version of Node.js are you using?

v16.10.0

Amplify CLI Version

7.6.3

What operating system are you using?

Mac

Amplify Categories

api

Amplify Commands

Not applicable

Describe the bug

When running $ amplify mock api, Amplify CLI exports compiled resolvers to amplify/backend/api/{API NAME}/resolvers/. Even after I exit $ amplify mock apiusing Ctrl+C, amplify/backend/api/{API NAME}/resolvers/ files which are not custom VTL but generated automatically by Amplify CLI remain. This causes overwriting all the resolvers and fixing VTLs as I run $ amplify mock api at first time.

Expected behavior

When running $ amplify mock api, Amplify CLI exports compiled resolvers to amplify/backend/api/{API NAME}/build/resolvers/.

Reproduction steps

  1. $ amplify init
  2. $ amplify add api specifying IAM and API Key for auth method.
  3. edit schema.graphql as below
type Todo @model 
  @auth(rules: [
      { allow: public, provider: iam }
    ]) 
{
  id: ID! 
  name: String!
  description: String!
}
  1. $ amplify mock api
  2. check amplify/backend/api/{API NAME}/build/resolvers/Mutation.createTodo.auth.1.req.vtl. Only IAM Authorization is allowed and API Key Authorizations is not allowed.
## [Start] Authorization Steps. **
$util.qr($ctx.stash.put("hasAuth", true))
#set( $inputFields = $util.parseJson($util.toJson($ctx.args.input.keySet())) )
#set( $isAuthorized = false )
#set( $allowedFields = [] )
#if( $util.authType() == "API Key Authorization" )
$util.unauthorized()
#end
#if( $util.authType() == "IAM Authorization" )
  #if( $ctx.identity.userArn == $ctx.stash.unauthRole )
    #set( $isAuthorized = true )
  #end
#end
#if( !$isAuthorized && $allowedFields.isEmpty() )
$util.unauthorized()
#end
#if( !$isAuthorized )
  #set( $deniedFields = $util.list.copyAndRemoveAll($inputFields, $allowedFields) )
  #if( $deniedFields.size() > 0 )
    $util.error("Unauthorized on ${deniedFields}", "Unauthorized")
  #end
#end
$util.toJson({"version":"2018-05-29","payload":{}})
## [End] Authorization Steps. **
  1. then edit schema.graphql as below during running $ amplify mock api
type Todo @model 
  @auth(rules: [
      { allow: public, provider: iam }
      { allow: public, provider: apiKey }
    ]) 
{
  id: ID! 
  name: String!
  description: String!
}
  1. Exit $ amplify mock api using Ctrl+C.
  2. Check amplify/backend/api/{API NAME}/build/resolvers/Mutation.createTodo.auth.1.req.vtl content is not changed. I expect the filed changed as below. API Key Authorizations should be added.
## [Start] Authorization Steps. **
$util.qr($ctx.stash.put("hasAuth", true))
#set( $inputFields = $util.parseJson($util.toJson($ctx.args.input.keySet())) )
#set( $isAuthorized = false )
#set( $allowedFields = [] )
#if( $util.authType() == "API Key Authorization" )
  #set( $isAuthorized = true )
#end
#if( $util.authType() == "IAM Authorization" )
  #if( $ctx.identity.userArn == $ctx.stash.unauthRole )
    #set( $isAuthorized = true )
  #end
#end
#if( !$isAuthorized && $allowedFields.isEmpty() )
$util.unauthorized()
#end
#if( !$isAuthorized )
  #set( $deniedFields = $util.list.copyAndRemoveAll($inputFields, $allowedFields) )
  #if( $deniedFields.size() > 0 )
    $util.error("Unauthorized on ${deniedFields}", "Unauthorized")
  #end
#end
$util.toJson({"version":"2018-05-29","payload":{}})
## [End] Authorization Steps. **

GraphQL schema(s)

# Put schemas below this line


Log output

# Put your logs below this line


Additional information

Once after $ amplify mock api, amplify/backend/api/{API NAME}/resolvers directory is created and $ amplify api gql-compile starts to not work well.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
jaga810commented, Dec 14, 2021

@lazpavel I found another reproduction step. If you modify schema.graphql during $ amplify mock api, resolvers in amplify/backend/api/{API NAME}/resolvers/ remain after exiting $ amplify mock api.

And I wonder if it is expected behavior that $ amplify mock api export resolvers in amplify/backend/api/{API NAME}/resolvers/ not in amplify/backend/api/{API NAME}/build/resolvers/.

1reaction
lazpavelcommented, Dec 14, 2021

Hi @jaga810, thank you for providing reproduction steps. Currently when mock api exits it only removes the templates that are the same as the ones in the build directory in order to keep the custom ones. I believe there is room for a better DX here.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring resolvers (VTL) - AWS AppSync
GraphQL resolvers connect the fields in a type's schema to a data source. Resolvers are the mechanism by which requests are fulfilled.
Read more >
Resolvers - Apollo GraphQL Docs
Apollo Server needs to know how to populate data for every field in your schema so that it can respond to requests for...
Read more >
Advanced workflows - Mocking and testing - AWS Amplify Docs
Learn how to quickly test and debug without pushing all changes in your Amplify project to the cloud. Use local mocking and testing...
Read more >
Restoring Previous instance of AWS Appsync schema
Let's say you have a simple schema.graphql… ... getTodo.res.vtl file to change the behavior of the resolver's response mapping template.
Read more >
Creating a useful GraphQL server using AWS Amplify
To run your schema locally, run amplify mock api in your terminal. ... form of .vtl files under amplify/backend/api/[api-name]/resolvers/ ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found