-
Notifications
You must be signed in to change notification settings - Fork 194
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Correct way to get ‚_version‘ - field in Amplify Models for updating GraphQL #1614
Comments
Hi @rereiusch, when using a conflict resolution enabled API for DataStore, you should use |
Hi @lawmicha, sorry for the late answer. Thank you for your message! I've already tried using
As I read from the console, I still have to provide a _version, even when using DataStore, and then I hit the original problem as I cannot access it through the schema. Thank you very much! |
Hi @rereiusch, were you able to update the backend with or without conflict resolution? Missing fields like "is undefined" for the three conflict resolution fields "_version", "_deleted", "_lastChangedAt" appears that the backend might be set to no conflict resolution enabled. Can you please provide us the schema or any sort of screenshot from your set up? This way we can try it out and see what's going on |
Hi @lawmicha, I've tried it both ways (conflict solution enabled and disabled) the last few days using When it's enabled, the following is happening:
Afterward, the console says that it starts unsubscribing from everything again. About the schema, I've created it with Amplify Studio like the screenshot below (in this case the User - Model, which I tried to update). By deploying Amplify created all the mutations and queries, as it should. The final output for the user model in the AppSync Console is the following:
I hope this helps. If you need anything more, please let me know! Thank you very much for your help! :) |
I wonder in the subscription is retrieving you the _version as null or the real one from dynamodb? |
Thank you for providing a screenshot of the schema you are using. We can use this to verify that the issue is fixed by the changes we have upcoming. I believe this is the same issue as #1753. The selection set sent from Studio is different from the selection set created by the iOS DataStore client, thus iOS client is unable to decode the mutation response successfully. Please track #1753 (comment) |
Changes are released in v2, we are waiting for codegen changes to be released to verify the fix - https://github.com/aws-amplify/amplify-codegen |
The feature is released in Here is how my cli.json looks like: {
"features": {
"graphqltransformer": {
"addmissingownerfields": true,
"improvepluralization": false,
"validatetypenamereservedwords": true,
"useexperimentalpipelinedtransformer": true,
"enableiterativegsiupdates": true,
"secondarykeyasgsi": true,
"skipoverridemutationinputtypes": true,
"transformerversion": 2,
"suppressschemamigrationprompt": true,
"securityenhancementnotification": false,
"showfieldauthnotification": false,
"usesubusernamefordefaultidentityclaim": true,
"usefieldnameforprimarykeyconnectionfield": false,
"enableautoindexquerynames": true,
"respectprimarykeyattributesonconnectionfield": true,
"shoulddeepmergedirectiveconfigdefaults": false,
"populateownerfieldforstaticgroupauth": true
},
"frontend-ios": {
"enablexcodeintegration": true
},
"auth": {
"enablecaseinsensitivity": true,
"useinclusiveterminology": true,
"breakcirculardependency": true,
"forcealiasattributes": false,
"useenabledmfas": true
},
"codegen": {
"useappsyncmodelgenplugin": true,
"usedocsgeneratorplugin": true,
"usetypesgeneratorplugin": true,
"cleangeneratedmodelsdirectory": true,
"retaincasestyle": true,
"addtimestampfields": true,
"handlelistnullabilitytransparently": true,
"emitauthprovider": true,
"generateindexrules": true,
"enabledartnullsafety": true,
"generatemodelsforlazyloadandcustomselectionset": true
},
"appsync": {
"generategraphqlpermissions": true
},
"latestregionsupport": {
"pinpoint": 1,
"translate": 1,
"transcribe": 1,
"rekognition": 1,
"textract": 1,
"comprehend": 1
},
"project": {
"overrides": true
}
},
"debug": {
"shareProjectConfig": false
}
} Let us know if this solves your use case. |
While I can create new Input for my Database using the GraphQL with Amplify API, I cannot update it, the console gives me this Error:
Amplify.GraphQLError(message: "Value for field '$[_version]' must be a number."
I know that Amplify needs a Version because of the enabled conflict detection. When I disable it, it would just work fine, but then Amplify Studio breaks and I cannot edit anything until I reenable it.
I’m trying to provide the version number with following function:
The problem is, that if I wanna update a field, I need to provide the correct current version number from the serverside, otherwise the entry won’t get overwritten. So I need to fetch the current version entry for the model I want to update from the database.
And now to the core of my question:
When I check my Schema in the AppSync Console, every models already has the field ‚_version‘. But when I pull the the whole Backend into my App, neither the schema.graphql file contain the field, nor my Amplify Models in Swift get updated. So I cannot fetch the current version and in the aftermath cannot update the entry at all.
What is the right way to fetch the current version? All i could find so far is to just disable the conflict detection #1075, but that’s not the best option for me. Also writing the '_version' field into the Swift model by hand, which actually would work, isn't suitable, as the file gets overwritten every time when the Backend got pulled.
Thank you very much for any help in advance!
Have a great day!
The text was updated successfully, but these errors were encountered: