Note: If your question is regarding the AWS Amplify Console service, please log it in the
official AWS Amplify Console forum
Which Category is your question related to?
Either this is a bug or better documentation on how to overwrite resolvers
Amplify CLI Version
You can use amplify -v to check the amplify cli version on your system
4.5.0
What AWS Services are you utilizing?
Auth & API & Lambda
Provide additional details e.g. code snippets
I need to overwrite the Input to a mutation resolver to add extra values to the fields (I am using a PreTokenGeneration Lambda to insert an extra group to achieve multi-tenancy).
this is my graphql
type data
@model
@auth(
rules: [
{
allow: groups
groups: ["Managers"]
queries: [get, list]
mutations: [create, update, delete]
}
{
allow: groups
groups: ["Employees", "others"]
queries: [get, list]
mutations: null
}
]
) {
id: ID!
title: String!
tenant: String
}
type PrivateNote @model @auth(rules: [{ allow: owner }]) {
id: ID!
content: String!
}
I have created a _Mutation.createData.req.vtl_ file in the resolver directory and it has some extra lines to the original one
When I do Amplify Push, I see the new modified file under Amplify->build->resolvers directory
But the resolver on AppSync is never updated.
Following the advice of someone, I went through the rabbit hole of custom resolvers, very little documentation on how to do it, and after hours I got the dreadful "Two resolvers for the same field" and I gave up.
The documentation suggests placing the files in the resolver directory should work but it is not!
Hello, it sounds like you are missing the "Add a resolver resource to a stack in the stacks/ directory."
I have followed this example and it is working fine for me:
https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js#add-a-custom-resolver-that-targets-a-dynamodb-table-from-model
Well, not sure if that step is necessary only for "added" resolvers, or is it also needed for overwritten ones.
I need to overwrite the Input to a mutation resolver to add extra values to the fields (I am using a PreTokenGeneration Lambda to insert an extra group to achieve multi-tenancy).
Transformer has a way to specify custom claims (identityClaim and groupClaim) as documented here, if you just need to insert that value into the the DynamoDB table. This would keep all the auth rules you have in sync where as custom resolvers, you would make sure the auth logic gets updated when the @auth rules are updated.
I need to overwrite the Input to a mutation resolver to add extra values to the fields (I am using a PreTokenGeneration Lambda to insert an extra group to achieve multi-tenancy).
Transformer has a way to specify custom claims (
identityClaimandgroupClaim) as documented here, if you just need to insert that value into the the DynamoDB table. This would keep all the auth rules you have in sync where as custom resolvers, you would make sure the auth logic gets updated when the@authrules are updated.
That is pretty cool but won't work with me, I am doing multi-tenancy so inserting in each record a 'tenant' field that I get from the group, which gets injected from the user custom attributes, the queries will filter against that field later.
Well, not sure if that step is necessary only for "added" resolvers, or is it also needed for overwritten ones.
Nobody is 'sure', that is my definition of 'needs documentation'!
Hello, it sounds like you are missing the "Add a resolver resource to a stack in the stacks/ directory."
I have followed this example and it is working fine for me:
https://aws-amplify.github.io/docs/cli-toolchain/graphql?sdk=js#add-a-custom-resolver-that-targets-a-dynamodb-table-from-model
That document is as clear as mud, what is the `ApiId.ref' ? how is that related to the parameters on the top section of the _CustomResources.json_
Do we have any examples of that? and as you said in your other document is there any documentation of this? each error takes between 10 to 12 minutes with messages that are very cryptic like this

Hello @c0dingarchit3ct,
AppSyncApiId leave it as is. That string is auto replaced when pushing to backend.
Replace with your data:
“Resources”: { and before the “type”.Add as many resolvers as you need inside the “Resources” { } tags, separated by commas:
{
"AWSTemplateFormatVersion": "2010-09-09",
"Description": "An auto-generated nested stack.",
"Metadata": {},
"Parameters": ...
...
...
...
”Resources” : {
“EmptyResource” : {
...
},
“Resolver1name” : {
“type” : "AWS::AppSync::Resolver",
...
},
Resolver2name” : {
“type” : "AWS::AppSync::Resolver",
...
}
}
}
Thank you @Soek22 That was very precise, I have finally concluded that this was 'CloudFormation' so I went to gain more information and came to the same conclusion.
Good news: I gained some cloudformation knowledge and spent some time looking at the Amplify generated stack
Bad news, I am in the 'Only one resolver is allowed per field'?
I tried to delete the resolver in AWS, that didn't work
I even tried to create a new environment and that did not work!
I read somewhere in #862 that this is by design! I am not sure how is that a decision that makes sense? being worried about breaking changes, you introduce something that will force a change to every table in my App and break everything else? the field in question is the Mutation 'createData' that creates the record, other fields will be ListDatas and getData! this is a sample App I am trying to play with, my current App has 4 different types, of which I need to replace all create, list & get ? that is 12 fields that I have to delete and then push and then introduce?

I have found out that there was no need to modify the Custom Resources at all, I had to put the files in the 'resolvers' directory and make sure they match the names!. again the documentation sucks but alas, at least it is working now!
Most helpful comment
I have found out that there was no need to modify the Custom Resources at all, I had to put the files in the 'resolvers' directory and make sure they match the names!. again the documentation sucks but alas, at least it is working now!