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(@aws-amplify/datastore): update mutation input - diff with DB instead of patches #7935

Merged
merged 1 commit into from
Mar 25, 2021

Conversation

iartemiev
Copy link
Member

@iartemiev iartemiev commented Mar 14, 2021

Issue #, if available:
#7840

This PR changes the way we derive the correct update mutation input when using DataStore. Relying on Immer patches makes it difficult to resolve field data for connections and to include the correct fields when updating relational data. E.g., in the linked issue. Using a diff between the updated record and the previous record is a simpler and more reliable approach.

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@iartemiev iartemiev added the DataStore Related to DataStore category label Mar 14, 2021
@codecov
Copy link

codecov bot commented Mar 14, 2021

Codecov Report

Merging #7935 (e7a087a) into main (63dd9c3) will decrease coverage by 0.00%.
The diff coverage is 94.87%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7935      +/-   ##
==========================================
- Coverage   74.24%   74.24%   -0.01%     
==========================================
  Files         215      215              
  Lines       13474    13471       -3     
  Branches     2647     2647              
==========================================
- Hits        10004    10001       -3     
  Misses       3272     3272              
  Partials      198      198              
Impacted Files Coverage Δ
packages/datastore/__tests__/helpers.ts 100.00% <ø> (ø)
packages/datastore/src/storage/storage.ts 72.58% <75.00%> (-1.07%) ⬇️
packages/datastore/src/datastore/datastore.ts 78.15% <100.00%> (-0.28%) ⬇️
...tastore/src/storage/adapter/AsyncStorageAdapter.ts 77.95% <100.00%> (-0.09%) ⬇️
.../datastore/src/storage/adapter/IndexedDBAdapter.ts 78.28% <100.00%> (-0.13%) ⬇️
packages/datastore/src/util.ts 81.42% <100.00%> (+1.02%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 63dd9c3...e7a087a. Read the comment docs.

@lgtm-com
Copy link

lgtm-com bot commented Mar 14, 2021

This pull request introduces 1 alert when merging 075a95e into 0218cf5 - view on LGTM.com

new alerts:

  • 1 for Unused variable, import, function or class

@iartemiev iartemiev force-pushed the ds-update-mutation-fix branch 2 times, most recently from 2012fe9 to cdf0300 Compare March 19, 2021 12:31
Copy link
Contributor

@amhinson amhinson left a comment

Choose a reason for hiding this comment

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

LGTM 👍


// It is me
if (id === model.id) {
// Even if the parent is an INSERT, the child might not be, so we need to get its key

Choose a reason for hiding this comment

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

Could you explain this a little more for me? Is this a cascading save method? Just trying to figure out why you are talking about parent/child here.

Copy link
Member Author

@iartemiev iartemiev Mar 25, 2021

Choose a reason for hiding this comment

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

Yes, exactly this is cascading save logic.

FWIW I just slightly refactored it to return the locally stored record (i.e., the previous state that we then diff against in the Storage Class) in the [StorageAdapter].save method. That comment and most of the business logic were already there, this PR is not changing the cascading save logic itself.

Choose a reason for hiding this comment

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

Interesting. We don't have cascading save on Android (and I don't think on iOS either). We should probably add that to our roadmap.

Copy link

@richardmcclellan richardmcclellan left a comment

Choose a reason for hiding this comment

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

Overall, this looks good! Very similar to the Android implementation. I just had one minor question for you (above), and as mentioned in Slack, please confirm that when update mutations are created while offline, they are properly sent to AppSync when they come back online! As long as that works properly, ship it!

@github-actions
Copy link

This pull request has been automatically locked since there hasn't been any recent activity after it was closed. Please open a new issue for related bugs.

Looking for a help forum? We recommend joining the Amplify Community Discord server *-help channels or Discussions for those types of questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
DataStore Related to DataStore category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants