-
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 delivering "stale" results to ObservableQuery. #6058
Conversation
Codecov Report
@@ Coverage Diff @@
## master #6058 +/- ##
==========================================
- Coverage 95.37% 95.36% -0.02%
==========================================
Files 88 89 +1
Lines 3653 3666 +13
Branches 903 872 -31
==========================================
+ Hits 3484 3496 +12
Misses 146 146
- Partials 23 24 +1
Continue to review full report at Codecov.
|
if (errorPolicy === 'all' && hasGraphQLErrors) { | ||
resultFromStore.errors = graphQLErrors; | ||
} else if (isNonEmptyArray(diff.missing) && | ||
!equal(diff.result, {})) { |
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.
My reasoning for this !equal(diff.result, {})
check: results where zero fields were successfully read seem truly useless, and thus should not be reported to the client as errors, but partially successful reads with a few missing fields should be reported as errors.
88da9e5
to
a3f9d18
Compare
2762de3
to
14f2719
Compare
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.
This all looks excellent @benjamn - and the new missing field logging is going to be super helpful! 🎉
This new MissingFieldError type provides more information about the location where the error occurred within the result object, while also hiding the InvariantError type as an implementation detail. It's important to continue using the InvariantError type internally to give rollup-plugin-invariant a chance to strip the error messages from production builds.
14f2719
to
788517f
Compare
This functionality was introduced in PR #6058 (beta.43), and was temporarily removed by my refactoring PR #6221. I believe these warnings can be improved, especially since they are pretty noisy right now, but I wanted to preserve existing functionality before trying to figure out a better way to report missing fields. Any/all ideas and feedback welcome.
One of the most counterintuitive and confusing behaviors of Apollo Client is to silently re-deliver previous results whenever an incomplete result is read from the cache here:
Consider how pointless this is: we obtain
observableQuery.getLastResult()
and then send it immediately back to theObservableQuery
, just because it doesn't seem safe to send the incompletediff.result
.Instead, we should never be sending stale or incomplete results to the
ObservableQuery
. And instead of silently dropping the stale results, we should report appropriate errors to theObservableQuery
viaobserver.error
, so that the application can handle them. That's what this PR does.I have not finished validating these changes against @ahrnee's reproduction in #5991 (hence the WIP status of the PR), but that's my first priority tomorrow.