-
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
Avoid voiding result.data
in ObservableQuery#getCurrentResult
when !diff.complete
#8642
Conversation
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.
Great fix @benjamn!
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 small and smooth brain is unable to understand how methods like getLastResult()
, resetLastResult()
and isDifferentFromLastResult()
are supposed to be used. How would we communicate their purpose to users who directly call client.watchQuery()
?
Nevertheless, if this fixes issues for users, I guess it should be merged.
f14bc92
to
be29be7
Compare
LGTM so I can rebase against this in #8596 |
This change fixes issue #8620, by not clobbering `result.data` whenever `diff.complete` is false, but introduces other problems (test failures) that I will solve in later commits.
This refactoring should have no observable consequences, since these are all `private` properties of `ObservableQuery`.
I might prefer the default behavior to be reversed (variables must match by default), but these are `public` methods of `ObservableQuery`, so we should be careful to preserve the same behavior when `getLastResult` or `getLastError` are called with no arguments.
This test was previously delivering a `loading: false` result with neither `data` nor `error` defined, and now it delivers the correct data. Progress!
This resolves the concern I raised in this comment: #8642 (comment)
be29be7
to
c834089
Compare
PR #8422 (released in
@apollo/client@3.4.0-rc.15
) attempted to solve issue #7978 (reported by @dylanwulf) by relying onqueryInfo.getDiff()
to obtain results appropriate for the currentvariables
, rather than relying on thelastResult
stored by theObservableQuery
(which may have been obtained using differentvariables
).While this solution appeared to resolve #7978, it introduced a new bug (reported in #8620 by @maxsalven) because the following code now runs unconditionally:
apollo-client/src/core/ObservableQuery.ts
Lines 205 to 208 in bd03ff0
Whenever
!(diff.complete || this.options.returnPartialData)
, this code clobbersresult.data
withvoid 0
, even thoughresult.data
might provide useful information. In the case of #8620, that clobbered information is the missing network result for the A query.Ideally, we should leave
result.data
unmodified except whendiff.result
is used, as follows:apollo-client/src/core/ObservableQuery.ts
Lines 205 to 207 in 1b1f085
This change helps with issue #8620, but introduces some new test failures, because some of the
result.data
objects that are now delivered (instead ofvoid 0
) were obtained using different/stalevariables
than the currentthis.options.variables
. In other words, these test failures can be prevented if we finish fixing #7978, because the previous result will be appropriately ignored bygetCurrentResult
when thevariables
have changed.The rest of the commits in this PR fix those tests by tracking a snapshot of the original
variables
associated with the last result, so thegetCurrentResult
method can avoid usingthis.last.result
ifthis.last.variables
no longer matchthis.options.variables
.I also considered reverting PR #8422 and building back up to a better solution for #7978, but #8422 wasn't all bad, and I was able to make everything work more easily and cleanly with the current approach.