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

Throw when writing inconsistent query/data to InMemoryCache. #6055

Merged
merged 3 commits into from
Mar 17, 2020

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Mar 16, 2020

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 // XXX comment 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.

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.
@benjamn benjamn force-pushed the error-on-invalid-cache-writes branch from 05c5fee to 7282a5b Compare March 16, 2020 21:20
Comment on lines -240 to -243
// 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(
Copy link
Member Author

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.

Copy link
Member

@hwillson hwillson left a 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!

src/__tests__/ApolloClient.ts Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Mar 17, 2020

Codecov Report

Merging #6055 into master will increase coverage by 0.04%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
src/cache/inmemory/policies.ts 100.00% <ø> (ø)
src/utilities/testing/wrap.ts 35.71% <ø> (-23.38%) ⬇️
src/cache/inmemory/readFromStore.ts 100.00% <100.00%> (ø)
src/cache/inmemory/writeToStore.ts 100.00% <100.00%> (+2.35%) ⬆️
src/core/QueryManager.ts 97.69% <100.00%> (+0.01%) ⬆️
src/utilities/graphql/directives.ts 100.00% <100.00%> (ø)

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 f0fc1e7...e51f1f7. Read the comment docs.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants