-
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
Call nextFetchPolicy
with "variables-changed" even if there is a fetchPolicy
option specified.
#11626
Conversation
…etchPolicy` specified. fixes #11365
🦋 Changeset detectedLatest commit: 014d370 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
size-limit report 📦
|
✅ Deploy Preview for apollo-client-docs ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
(options.fetchPolicy === oldFetchPolicy || | ||
// A `nextFetchPolicy` function has even higher priority, though, | ||
// so in that case `applyNextFetchPolicy` must be called. | ||
typeof options.nextFetchPolicy === "function") | ||
) { | ||
this.applyNextFetchPolicy("variables-changed", options); | ||
if (newNetworkStatus === void 0) { |
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.
It seems that lines 917-920
(
if (newNetworkStatus === void 0) {
newNetworkStatus = NetworkStatus.setVariables;
}
could be removed completely without failing any test. In fact, the new network status is set as part of QueryInfo.init
.
I did not remove it, though, to prevent any unforseen consequences - but wanted to have noted it somewhere.
/release:pr |
A new release has been made for this PR. You can install it with |
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.
I had a small comment about the test, but overall I think this change makes sense. Let's get this in 3.11!
link, | ||
}); | ||
|
||
const fetchQueryByPolicySpy = jest.spyOn( |
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.
While I am beginning to understand the purpose of checking on whether this is called, I'm curious if we even need this. Would it be enough to check that observable.options.fetchPolicy
is set to the correct value like you have below and trust that ObservableQuery
does the right thing with it? I'd be ok delegating the testing of that behavior in ObservableQuery
tests. On top of that, this makes it a tad more difficult to refactor any of that internal private logic since changes to this API (which are non-breaking) would require changes to this test. If we can avoid that at all possible, that would be awesome.
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.
Would it be enough to check that observable.options.fetchPolicy is set to the correct value like you have below and trust that ObservableQuery does the right thing with it?
Rereading the test: observable.options.fetchPolicy
changes multiple times - so we can't tell for sure if we assert on an intermediate or the final value.
The
// first network request triggers with initial fetchPolicy
expectQueryTriggered(1, "network-only");
could probably not be asserted in another way, since it changes around too fast.
=> I can't think of another way of testing that. I also hate that we test an internal detail, but I fear we can't avoid it here.
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.
On a kinda-positive note, we have an abstraction for mocking this in tests - I'll use that. At least then, if we break internals, they will do everywhere in a consistent matter.
import { mockFetchQuery } from "../../../core/__tests__/ObservableQuery";
Hi @phryneas! I just wanted to note that this is a breaking change for my team so I was wondering if you would be able to document this as a breaking/disruptive change in the changelog? Our implementation of Also, I feel that the
This part of the text mentions that the default behavior for variables changing is to reset the fetchPolicy to its initial value. However, this text does not mention that implementing your own |
Ugh, yeah :/ Tbh., we're a bit between a rock and a hard place with Right now we only have this out in an RC, so we can definitely still work on the wording, and also adjust some docs. I'll put it on our team agenda for next Monday so we can discuss this. Thank you for bringing this up! |
fixes #11365