Closed dobeerman closed 1 year ago
Hi @dobeerman - Could you provide the resolver names containing the id
field? The only resolver I see contains id
field with custom primary key is Mutation.createModel.init.1.req.vtl
- It assigns default value to id
field if it is defined on the model. However this doesn't affect the functionality in any way, the model should work as expected - the dynamoDB table should have the partition and sort keys as configured using primaryKey
directive. Please let us know if you have any questions.
Hi @sundersc
Firstly, thanks for your quick reply.
This is the auto-generated (by amplify api gql-compile
command) Mutation.createProfile.req.vtl
file
and this is the auto-generated by amplify codegen models
command model
So, as you can see, id
field still persists on the model and in the resolver.
Am I missed something? :thinking:
@dobeerman - It looks like conflict resolution is enabled (using DataStore) on your project. Please correct me if I'm wrong.
DataStore expects id
field as primary key (Docs ref below)
https://docs.amplify.aws/lib/datastore/relational/q/platform/flutter/
You can safely ignore the id
references in the resolver.
## This assigns value to id field if primary key is not explicity defined
#if( $ctx.stash.metadata.modelObjectKey )
$util.qr($PutObject.put("key", $ctx.stash.metadata.modelObjectKey))
#else
#set( $Key = {
"id": $util.dynamodb.toDynamoDB($mergedValues.id)
} )
$util.qr($PutObject.put("key", $Key))
#end
@sundersc thank you for the clarification! Now I'm clear.
The only one question remains: do I still need to specify id
when I update/delete the item?
Hi @dobeerman, Sorry for the delay. Yes, you still need to specify id to update and delete the item.
Before opening, please confirm:
How did you install the Amplify CLI?
yarn
If applicable, what version of Node.js are you using?
No response
Amplify CLI Version
9.1.0
What operating system are you using?
Ubuntu 20.04
Did you make any manual changes to the cloud resources managed by Amplify? Please describe the changes made.
We are on local storage and did not pushed to the cloud yet.
Amplify Categories
api
Amplify Commands
codegen
Describe the bug
With specified
@primaryKey
amplify api gql-compile
generates incorrect resolvers and respectively,amplify codegen models
generates incorrect models that still includeid
s.Expected behavior
Default
id
field is overridden with the specified as@primaryKey
one.Reproduction steps
@primaryKey
directiveamplify api gql-compile
id
fieldGraphQL schema(s)
Project Identifier
5716387d43d0cb85d4d69e4e2309abcf
Log output
Additional information
Flutter project