-
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
Throw when writing inconsistent query/data to InMemoryCache. #6055
Conversation
0c4a6ef
to
05c5fee
Compare
The changes in src/cache/inmemory/writeToStore.ts make it an error rather than just a warning to write a result into the InMemoryCache with missing data fields, addressing an old TODO that was grandfathered into the StoreWriter class. This will be a *breaking change* for any code that was previously ignoring the warning, which means this change is appropriate for Apollo Client 3.0, but likely will not require any migration steps for most applications. While updating the relevant tests, I realized that the withWarning pattern could (and should) be eliminated.
05c5fee
to
7282a5b
Compare
// XXX We'd like to throw an error, but for backwards compatibility's sake | ||
// we just print a warning for the time being. | ||
//throw new WriteError(`Missing field ${resultFieldKey} in ${JSON.stringify(result, null, 2).substring(0, 100)}`); | ||
invariant.warn( |
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.
Here's the old // XXX
comment that this PR addresses.
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.
Looks great @benjamn 🎉 - thanks!
Codecov Report
@@ Coverage Diff @@
## master #6055 +/- ##
==========================================
+ Coverage 95.37% 95.42% +0.04%
==========================================
Files 88 88
Lines 3658 3650 -8
Branches 863 891 +28
==========================================
- Hits 3489 3483 -6
+ Misses 148 146 -2
Partials 21 21
Continue to review full report at Codecov.
|
The changes in
src/cache/inmemory/writeToStore.ts
make it an error rather than just a warning to write a result into theInMemoryCache
with missing data fields, addressing an old// XXX
comment that was grandfathered into theStoreWriter
class.This will be a breaking change for any code that was previously ignoring the warning, which means this change is appropriate for Apollo Client 3.0, but likely will not require any migration steps for most applications.
While updating the relevant tests, I realized that the
withWarning
pattern could (and should) be eliminated.