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

Improve processing of options.nextFetchPolicy #8465

Merged
merged 11 commits into from
Jul 9, 2021

Conversation

benjamn
Copy link
Member

@benjamn benjamn commented Jul 7, 2021

These changes make the processing of options.nextFetchPolicy (introduced in #6712) more predictable, in the following ways:

  • The options.nextFetchPolicy property will no longer be removed after it's applied for the first time, allowing it to continue to apply any time a different fetchPolicy is (temporarily) used.
  • The ObservableQuery#reobserve method is now more explicit about which kinds of reobservations get their own options and Concast observable, so those operations (for example, refetch and poll) no longer need to specify nextFetchPolicy (since their options are separate and will be discarded).
  • The applyNextFetchPolicy function is now called in only one place, fixing a regression that I identified in [v3.4 Regression] Changing variables uses nextFetchPolicy instead of fetchPolicy #8426 (comment).

Fixes the following issues (full list TBD):

@benjamn benjamn added this to the July 2021 milestone Jul 7, 2021
@benjamn benjamn self-assigned this Jul 7, 2021
@benjamn benjamn force-pushed the ObservableQuery-nextFetchPolicy-improvements branch from c2ba33f to e254dd4 Compare July 8, 2021 18:53
@benjamn benjamn marked this pull request as ready for review July 8, 2021 19:53
@benjamn benjamn requested a review from brainkim July 8, 2021 19:53
src/core/ObservableQuery.ts Outdated Show resolved Hide resolved
src/core/ObservableQuery.ts Show resolved Hide resolved
benjamn added 11 commits July 9, 2021 12:19
Despite my vague suggestion in the removed comments that deleting
options.nextFetchPolicy somehow helped make the fetchPolicy transition
idempotent (a concern that only matters when nextFetchPolicy is a
function), leaving options.nextFetchPolicy intact should also be
safe/idempotent in virtually all cases, including every case where
nextFetchPolicy is just a string, rather than a function.

More importantly, leaving options.nextFetchPolicy intact allows it to be
applied more than once, which seems to fix issue #6839.
ObservableQuery reobserve operations can either modify this.options and
replace this.concast with a Concast derived from those modified options,
or they can use a (shallow) copy of this.options to create a disposable
Concast just for the current reobserve operation, without permanently
altering the configuration of the ObservableQuery.

This commit clarifies which operations receive fresh options (and do not
modify this.concast): NetworkStatus.{refetch,poll,fetchMore}, as decided
in one place, by the ObservableQuery#reobserve method.

This list is subject to change, and I suspect we may end up wanting to
use criteria besides NetworkStatus in some cases. For now, NetworkStatus
seems to capture the cases we care about.

Since NetworkStatus.poll operations "run independently" now, with their
own shallow copy of this.options, the forced fetchPolicy: "network-only"
no longer needs to be reset by nextFetchPolicy. More generally, since
polling no longer modifies the ObservableQuery options at all, the
interaction betwee polling and other kinds of network fetches should be
less complicated after this commit.
This change seems consistent with the goals of #7437, though variables
can be changed without calling ObservableQuery#setVariables.
Specifying options.nextFetchPolicy is unnecessary because refetch
operations receive a (disposable) copy of the ObservableQuery options,
so options.fetchPolicy does not need to be reset.
@benjamn benjamn force-pushed the ObservableQuery-nextFetchPolicy-improvements branch from a198072 to 8a98eb9 Compare July 9, 2021 16:21
@benjamn benjamn merged commit 3e3a2e7 into release-3.4 Jul 9, 2021
@benjamn benjamn deleted the ObservableQuery-nextFetchPolicy-improvements branch July 9, 2021 16:24
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.

watchQuery defaultOptions are unset when query variables change (specifically nextFetchPolicy)
3 participants