Skip to content
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

fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model #4084

Merged
merged 1 commit into from
Nov 9, 2023

Conversation

Jordan-Nelson
Copy link
Member

Issue #, if available: #3649

Description of changes:

  • When event type is EventType.create and the model already exists in the list, evaluate if the model has changed

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Comment on lines +92 to +103
} else if (currentItem != newItem) {
// Update the item in the list. This is a "new" item, but it already
// exists in the list with a different value. This is the result of
// the item being created on this device and App Sync returning an
// updated item during the create mutation. This can happen when using
// custom resolvers.
updatedSortedList = _sortedList.copy()
..updateAtSorted(
currentIndex,
newItem,
);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

note: I refactored this and added comments to make it easier to understand but this code block is the only logic change. When the event type is EventType.create and the item value has changed (currentItem != newItem) the item in the list is updated with the new value. Previously this was ignored. This is problem when the model create response from App Sync contains an updated model, which is the case when using a custom resolver.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

question: is currentItem != newItem a sufficient comparison, like is it a deep equals?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, item is of type Model and we override the equality operator on models. For example, a typical Blog model would look like:

  @override
  bool operator ==(Object other) {
    if (identical(other, this)) return true;
    return other is Blog &&
        id == other.id &&
        _name == other._name &&
        DeepCollectionEquality().equals(_posts, other._posts);
  }

@Jordan-Nelson Jordan-Nelson marked this pull request as ready for review November 7, 2023 19:17
@Jordan-Nelson Jordan-Nelson requested a review from a team as a code owner November 7, 2023 19:17
@Jordan-Nelson Jordan-Nelson changed the title chore(datastore): emit snapshot when create results in an update fix(datastore): emit snapshot when create results in an update Nov 7, 2023
@Jordan-Nelson Jordan-Nelson changed the title fix(datastore): emit snapshot when create results in an update fix(datastore): emit observeQuery snapshot when model creation results in an updated model Nov 7, 2023
@Jordan-Nelson Jordan-Nelson changed the title fix(datastore): emit observeQuery snapshot when model creation results in an updated model fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model Nov 9, 2023
@Jordan-Nelson Jordan-Nelson merged commit c48f62d into main Nov 9, 2023
157 of 161 checks passed
@Jordan-Nelson Jordan-Nelson deleted the fix/datastore/observeQuery-resolver branch November 9, 2023 17:19
NikaHsn pushed a commit that referenced this pull request Dec 5, 2023
… results in an updated model (#4084)

chore: emit snapshot when create results in an update
NikaHsn pushed a commit that referenced this pull request Dec 5, 2023
- fix(api): GraphQL Model Helpers support lowercase model names #4143 (#4144)
- fix(authenticator): required phone number validator ([#4106](#4106))
- fix(core): pub docs ([#4049](#4049))
- fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model ([#4084](#4084))

Updated-Components: amplify_lints, Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
NikaHsn pushed a commit that referenced this pull request Dec 5, 2023
### Fixes
- fix(api): GraphQL Model Helpers support lowercase model names #4143 (#4144)
- fix(authenticator): required phone number validator ([#4106](#4106))
- fix(core): pub docs ([#4049](#4049))
- fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model ([#4084](#4084))

Updated-Components: amplify_lints, Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
NikaHsn pushed a commit that referenced this pull request Dec 6, 2023
… results in an updated model (#4084)

chore: emit snapshot when create results in an update
NikaHsn pushed a commit that referenced this pull request Dec 6, 2023
### Fixes
- fix(api): GraphQL Model Helpers support lowercase model names #4143 (#4144)
- fix(authenticator): required phone number validator ([#4106](#4106))
- fix(core): pub docs ([#4049](#4049))
- fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model ([#4084](#4084))

Updated-Components: amplify_lints, Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
NikaHsn pushed a commit that referenced this pull request Dec 6, 2023
### Fixes
- fix(api): GraphQL Model Helpers support lowercase model names #4143 (#4144)
- fix(authenticator): required phone number validator ([#4106](#4106))
- fix(core): pub docs ([#4049](#4049))
- fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model ([#4084](#4084))

Updated-Components: amplify_lints, Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
NikaHsn added a commit that referenced this pull request Dec 6, 2023
### Fixes
- fix(api): GraphQL Model Helpers support lowercase model names #4143 (#4144)
- fix(authenticator): required phone number validator ([#4106](#4106))
- fix(core): pub docs ([#4049](#4049))
- fix(datastore): emit observeQuery snapshot when model create mutation results in an updated model ([#4084](#4084))

Updated-Components: amplify_lints, Amplify Flutter, Amplify Dart, Amplify UI, DB Common, Secure Storage, AWS Common, Smithy, Worker Bee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants