A conflict resolution strategy is used to resolve conflicts during Update and Delete Mutations respectively. In order to use a specific strategy, one has to specify it in the call to
createDataSyncAPI for every model that they want to use the strategy with:
Graphback DataSync has three built-in conflict resolution strategies that come with it:
This strategy ensures that updates always resolve to whatever the client had sent, even in the event of a conflict. If the corresponding object has been deleted in the database, it is restored when the client tries to update it. For delete conflicts, the corresponding object is always deleted, regardless of if it had been updated since the client last fetched it.
This strategy ensures that in the event of a update conflict, the client's update will never overwrite any field that has changed since the client last fetched it. If the object has been deleted in the database, the client will be notified of it by way of a
ConflictError. For delete conflicts, the client is informed of the conflict via a
This strategy throws a
ConflictError whenever a client tries to change a field on a document, that has also been changed on the server since the client last fetched it.
Custom Conflict Strategy
A custom conflict resolution strategy can be created by implementing ConflictResolutionStrategy. As an example, take the implementation of the
resolveUpdate function, it can be seen that the resolved object's fields are always set to what the client updated in the event of an update conflict. It can also be seen that if the object has been deleted, it will be restored, along with the updates.
resolveDelete function, it can be seen that in the event of a delete conflict, the object is always deleted.
This error is thrown when a Conflict Resolution Strategy is unable to resolve the conflict, and needs the client to resolve it instead. It is a subclass of
Error with a
conflictInfo property which is of the
ConflictMetadata type. It can be created by passing a
ConflictMetadata object in it's constructor: