-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
Stop treating dangling references differently from empty objects. #6365
Merged
benjamn
merged 1 commit into
master
from
assume-dangling-references-refer-to-empty-objects
May 30, 2020
Merged
Stop treating dangling references differently from empty objects. #6365
benjamn
merged 1 commit into
master
from
assume-dangling-references-refer-to-empty-objects
May 30, 2020
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Question: When cache.read{Query,Fragment} encounters a dangling reference (one that does not currently refer to any normalized entity object in the cache), should the cache behave as if the (nonexistent) target of the reference was an empty object, and report any requested fields as missing, or should the cache generate some other kind of error that reflects the the absence of the whole object? I think we could answer this question either way, but I'm leaning towards the first option. Note: it's normal for the cache to end up with dangling references when whole entity objects are evicted, or when a reference is created (e.g. by toReference) without writing any data into the cache. Cleaning up dangling references is a tricky problem, requiring application-level reasoning, and not even always desirable, since the data could always come back into the cache later, restoring the validity of the reference. Previously, I thought it would be helpful to distinguish between the absence of an entity object and the object simply being empty, but I no longer think this distinction (which only affected the wording of the MissingFieldError description) matters very much, and we can simplify everything by adopting the following policy: > During cache reads, a dangling Reference should behave as much as possible like a Reference to an entity object that happens to contain zero fields. I'm optimistic this policy may help with issues like #6325. At the very least, this policy means there's now only one kind of MissingFieldError, which should reduce confusion.
hwillson
approved these changes
May 29, 2020
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 like this approach as well @benjamn - thanks!
benjamn
added a commit
that referenced
this pull request
Jun 1, 2020
…cts" This reverts commit c810713, introduced recently in PR #6365. My optimism that #6365 was an improvement seems to have been misplaced, since it caused the regression reported in #6368. We're too close to the AC3 RC/release to be floating risky changes like these without compelling justifications.
Merged
benjamn
added a commit
that referenced
this pull request
Jun 1, 2020
…cts" (#6371) This reverts commit c810713, introduced recently in PR #6365. My optimism that #6365 was an improvement seems to have been misplaced, since it caused the regression reported in #6368. We're too close to the AC3 RC/release to be floating risky changes like these without compelling justifications.
benjamn
added a commit
that referenced
this pull request
Jul 27, 2020
PR #6353 explains the rationale for switching to a cache-first FetchPolicy after an initial cache-and-network or network-only policy. When #6365 was implemented, options.fetchPolicy was examined only once, at the beginning of fetchQueryObservable, so the timing of changing options.fetchPolicy did not matter as much. However, fixing #6659 involves checking the current options.fetchPolicy whenever the QueryData class calls this.currentObservable.getCurrentResult(), so it's now more important to delay changing options.fetchPolicy until after the first network request has completed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Question: When
cache.read{Query,Fragment}
encounters a dangling reference (one that does not currently refer to any normalized entity object in the cache), should the cache behave as if the (nonexistent) target of the reference was an empty object, and report any requested fields as missing, or should the cache generate some other kind of error that reflects the the absence of the whole object?I think we could answer this question either way, but I'm leaning towards the first option.
Note: it's normal for the cache to end up with dangling references when whole entity objects are evicted, or when a reference is created (e.g. by
toReference
in aread
function) without writing any data into the cache. Cleaning up dangling references is a tricky problem, requiring application-level reasoning—and not even always desirable, since the data could always come back into the cache later, restoring the validity of the reference.Previously, I thought it would be helpful to distinguish between the absence of an entity object and the object simply being empty, but I no longer think this distinction (which only affected the wording of the
MissingFieldError
description) matters very much, and we can simplify everything by adopting the following policy:I'm optimistic this policy may help with issues like #6325. At the very least, it means there's now only one flavor of
MissingFieldError
, which should reduce confusion.