-
Notifications
You must be signed in to change notification settings - Fork 249
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
Conversation
} 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, | ||
); | ||
} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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);
}
… results in an updated model (#4084) chore: emit snapshot when create results in an update
- 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
### 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
… results in an updated model (#4084) chore: emit snapshot when create results in an update
### 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
### 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
### 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
Issue #, if available: #3649
Description of changes:
EventType.create
and the model already exists in the list, evaluate if the model has changedBy submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.