-
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
Updating cache triggers queries when fetchPolicy: cache-and-network is used #6833
Comments
I think I'm seeing a similar behavior when using the |
Based on the comment #6760 (comment) It seems that setting |
That fixed it for us! At least half :D We still are seeing some queries being re-fired when others resolve that affect the cache, even after applying the Edit: I'm not really able to repro this anymore, but I've been working on our merge functions lately and I think I might have "solved" it accidentally. If it happens again I'll try to come back and update this comment, or open a new issue with repro. |
@hinok I see you edited your comment, but I was curious what you meant by "unfortunately To your point about the difference in broadcasting behavior between |
@benjamn I edited my comment because I had a small issue on my side in btw it'd be nice to have a warning or info about If |
Totally agree that we need more examples of all this stuff! Although |
@hinok @sirugh With new ApolloClient({
link,
cache,
defaultOptions: {
watchQuery: {
nextFetchPolicy(lastFetchPolicy) {
if (lastFetchPolicy === "cache-and-network" ||
lastFetchPolicy === "network-only") {
return "cache-first";
}
return lastFetchPolicy;
},
},
},
}) It's important to use a function here, so you're only modifying Thanks in advance for testing out this new functionality and reporting any problems you encounter! |
|
Is this true? Can you repro in codesandbox? The query is effectively "changed" if the variables change, as in, it shouldn't even be the same cache entry because the key changed (unless you have some constant as the key). |
|
🤷🏼 Maybe this comment will help you? #7938 (comment) I'm not particularly invested in this, I just know that a new issue + sandbox repro + clear ask can give the maintainers a good starting point. There are a lot of moving parts in Apollo so a slimmed down repro in sandbox can be very helpful for folks trying to debug this issue. But you do you. Good luck! |
@sirugh Sorry I didn't mean to be passive aggressive. The issue I mentioned existed in versions after Thanks to the Apollo team for their hard work! |
Is the following global setting still required with the latests @apollo/client? If you do not add this setting what is the result?
|
This issue doesn't exist on
3.0.2
This issue exists on
>3.0.2
Intended outcome:
Update cache without firing network request while using
fetchPolicy: cache-and-network
.Actual outcome:
In the past there was a possibility to update cache without triggering network request by using
cache.writeData
etc.Now by using
cache.modify
, query is re-run and network request is fired.How to reproduce the issue:
Demo: https://codesandbox.io/s/sleepy-clarke-19944?file=/src/AddUser.js
Open https://e3odl.sse.codesandbox.io/ to start the apollo server used in the reproduction.
Important code
Users.js
AddUser.js
Versions
The text was updated successfully, but these errors were encountered: