-
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
Mutations with fetchPolicy: 'no-cache' still trigger refetchQueries #10238
Comments
This has affected my team as well. We have a note editor which periodically triggers api requests that look like this: client.mutate({
mutation: UpdateNoteMutation,
fetchPolicy: "no-cache",
variables: {
input: {
noteId,
},
},
}); The mutation triggers cache reconciliation, which can cause latency spikes when users are typing in our editor. Our workaround has been to modify it at the "client defaultOptions" level, but definitely not ideal: const newClient = new ApolloClient({
...
defaultOptions: {
mutate: {
// ApolloClient's QueryManager updates the cache if this is undefined because it's replaced
// with []. This will circumvent that issue.
// See: https://github.com/apollographql/apollo-client/issues/10238
//
// eslint-disable-next-line @typescript-eslint/no-explicit-any
refetchQueries: false as any,
},
},
}); I'm happy to share more info if that would be helpful! |
@bendenoz is this still an issue in the latest version of Edit: Based on reading the code in |
You don't even need The only workaround is to set |
I've opened a PR for a quick fix: #11515. Curious if you see any pitfals with this simple fix? |
Do you have any feedback for the maintainers? Please tell us by taking a one-minute survey. Your responses will help us understand Apollo Client usage and allow us to serve you better. |
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Intended outcome:
I'm trying to execute mutations without triggering cache reconciliation because I have a lot of data in the cache, which can take up to >5secs.
Actual outcome:
even with fetchPolicy: 'no-cache', I see refetchQueries triggered.
How to reproduce the issue:
Load > 8000 objects in the cache in one big list query, trigger a mutation on unrelated objects with fetchPolicy: 'no-cache'
Versions
3.7.0
I believe the problem is in
apollo-client/src/core/QueryManager.ts
Line 402 in 31fc8df
The test currently line 402 checks if refetchQueries exists, and since it appears to be an array it's always true, i guess it should be
mutation.refetchQueries.length > 0
My current workaround it to pass false
refetchQueries: false
to the mutate call but it fails the typescript constraintThe text was updated successfully, but these errors were encountered: