'Swift AWS Amplify get ‚_version‘ - field in Amplify Models
I’m currently developing the Backend for my iOS - App with AWS Amplify Studio. Everything works fine so far, I can create the models in Studio and pull the structure in my Swift Environment. But while I can create new Input for my Database, 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.
So noow I’m trying to provide the version number with following function:
func updateUser(user: User) {
Amplify.API.mutate(request: .updateMutation(of: user, version: 1)) { event in
switch event {
case .success(let result):
switch result {
case .success(let user):
print("Successfully updated user: \(user)")
case .failure(let error):
print("Got failed result with \(error.errorDescription)")
}
case .failure(let error):
print("Got failed event with error \(error)")
}
}
}
The problem is, that if you wanna update a field, you need to provide the correct current version number on the serverside, otherwise the entry won’t get overwritten. So you need to fetch the current version entry 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 doesn’t contain the fields, 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.
Does anybody have a solution for this? All i could found until now is to just disable the conflict detection, but that’s not the best option. Also writing the '_version' field into the Swift model by hand, which would 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!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
