Skip to content

Commit

Permalink
fix(@aws-amplify/datastore): handle merging queued create with incomi…
Browse files Browse the repository at this point in the history
…ng update (#8102)
  • Loading branch information
iartemiev authored Apr 15, 2021
1 parent a664adb commit d84cf34
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/datastore/src/sync/outbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,14 @@ class MutationEventOutbox {
if (incomingMutationType === TransformerMutationType.DELETE) {
await s.delete(this.MutationEvent, predicate);
} else {
// first gets updated with incoming's data, condition intentionally skipped
// first gets updated with the incoming mutation's data, condition intentionally skipped

// we need to merge the fields for a create and update mutation to prevent
// data loss, since update mutations only include changed fields
const merged = this.mergeUserFields(first, mutationEvent);
await s.save(
this.MutationEvent.copyOf(first, draft => {
draft.data = mutationEvent.data;
draft.data = merged.data;
}),
undefined,
this.ownSymbol
Expand Down

0 comments on commit d84cf34

Please sign in to comment.