All the VTL resolvers cannot be updated by modifying `schema.graphql` after Mocking.
See original GitHub issueBefore 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 api
using 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
$ amplify init
$ amplify add api
specifying IAM and API Key for auth method.- edit
schema.graphql
as below
type Todo @model
@auth(rules: [
{ allow: public, provider: iam }
])
{
id: ID!
name: String!
description: String!
}
$ amplify mock api
- 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. **
- 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!
}
- Exit
$ amplify mock api
using Ctrl+C. - 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:
- Created 2 years ago
- Comments:9 (4 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@lazpavel I found another reproduction step. If you modify
schema.graphql
during$ amplify mock api
, resolvers inamplify/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 inamplify/backend/api/{API NAME}/resolvers/
not inamplify/backend/api/{API NAME}/build/resolvers/
.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.