Versioning and conflict resolution


The @versioned directive adds object versioning and conflict resolution to a type. Do not use this directive when leveraging DataStore as the conflict detection and resolution features are automatically handled inside AppSync and are incompatible with the @versioned directive.

Note that @versioned is only supported in client code (statement and types) generated via AppSync codegen. @versioned is not supported by models generated via amplify codegen models. Use Amplify DataStore instead of @versioned to provide offline app data access with built-in conflict-resolution.


1directive @versioned(versionField: String = "version", versionInput: String = "expectedVersion") on OBJECT


Add @versioned to a type that is also annotate with @model to enable object versioning and conflict detection for a type.

1type Post @model @versioned {
2 id: ID!
3 title: String!
4 version: Int! # <- If not provided, it is added for you.

Creating a Post automatically sets the version to 1

1mutation Create {
2 createPost(input:{
3 title:"Conflict detection in the cloud!"
4 }) {
5 id
6 title
7 version # will be 1
8 }

Updating a Post requires passing the "expectedVersion" which is the object's last saved version

Note: When updating an object, the version number will automatically increment.

1mutation Update($postId: ID!) {
2 updatePost(
3 input:{
4 id: $postId,
5 title: "Conflict detection in the cloud is great!",
6 expectedVersion: 1
7 }
8 ) {
9 id
10 title
11 version # will be 2
12 }

Deleting a Post requires passing the "expectedVersion" which is the object's last saved version

1mutation Delete($postId: ID!) {
2 deletePost(
3 input: {
4 id: $postId,
5 expectedVersion: 2
6 }
7 ) {
8 id
9 title
10 version
11 }

Update and delete operations will fail if the expectedVersion does not match the version stored in DynamoDB. You may change the default name of the version field on the type as well as the name of the input field via the versionField and versionInput arguments on the @versioned directive.


The @versioned directive manipulates resolver mapping templates and will store a version field in versioned objects.