-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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(@aws-amplify/datastore): adds missing fields to items sent through observe/observeQuery #9973
Changes from 1 commit
305cc1c
aebf936
bca754a
5befcd5
0da12b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1145,24 +1145,32 @@ class DataStore { | |
handle = this.storage | ||
.observe(modelConstructor, predicate) | ||
.filter(({ model }) => namespaceResolver(model) === USER) | ||
.map( | ||
(event: InternalSubscriptionMessage<T>): SubscriptionMessage<T> => { | ||
// The `element` returned by storage only contains updated fields. | ||
// Intercept the event to send the `savedElement` so that the first | ||
// snapshot returned to the consumer contains all fields. | ||
// In the event of a delete we return `element`, as `savedElement` | ||
// here is undefined. | ||
const { opType, model, condition, element, savedElement } = event; | ||
|
||
return { | ||
opType, | ||
element: savedElement || element, | ||
model, | ||
condition, | ||
}; | ||
} | ||
) | ||
.subscribe(observer); | ||
.subscribe({ | ||
next: async item => { | ||
// the `element` doesn't necessarily contain all item details or | ||
// have related records attached consistently with that of a query() | ||
// result item. for consistency, we attach them here. | ||
|
||
let message = item; | ||
|
||
// as lnog as we're not dealing with a DELETE, we need to fetch a fresh | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: typo |
||
// item from storage to ensure it's fully populated. | ||
if (item.opType !== 'DELETE') { | ||
const freshElement = await this.query( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we make sure we're not sending ALL fields to AppSync with this change? For instance, when I implemented the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. I've added a test for this in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tested your changes locally, and it appears that the outgoing request is only sending updated fields 👍🏻 |
||
item.model, | ||
item.element.id | ||
); | ||
message = { | ||
...message, | ||
element: freshElement as T, | ||
}; | ||
} | ||
|
||
observer.next(message as SubscriptionMessage<T>); | ||
}, | ||
error: err => observer.error(err), | ||
complete: () => observer.complete(), | ||
}); | ||
})(); | ||
|
||
return () => { | ||
|
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.
If this is truly no longer needed, then it makes sense to revert ALL of the changes I made here. PR: #9617
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.
Not all changes; your other PR ported over the initial set of missing observe/observeQuery. That's highly valuable!
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.
Thanks for testing this!
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.
I just tested your changes, and it looks like on update, the first snapshot still preserves all fields.