-
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
[Docs] refetchQueries can fetch non active queries #11894
Comments
Hey @maon-fp 👋 It looks like you're using the object-based syntax in apollo-client/src/core/QueryManager.ts Lines 873 to 875 in a739dfd
The "active" queries refer to the |
Thanks for your answer. I was just irritated by the docs not matching my observed behavior.
As far as I understand the const ALL_ANIMALS = gql`
query AllAnimals {
animals {
id
name
}
}
`; |
I dug a bit into this and the problem is that the code here doesn't exclude "inactive" queries when trying to refetch queries by name apollo-client/src/core/QueryManager.ts Lines 891 to 896 in d914d68
It should likely instead be the following if (
fetchPolicy === "standby" ||
- (include === "active" && !oq.hasObservers())
+ (include !== "all" && !oq.hasObservers())
) {
return;
} That way if the query is "inactive" (aka has no observers) then it would not be included in the refetch However, if the query is not found it would warn later that it didn't it. Which is questionable apollo-client/src/core/QueryManager.ts Lines 934 to 945 in d914d68
In my case I often mean "refetch IF it active, otherwise, meh" |
@maon-fp apologies, coming back to this, I realize I misread your reproduction. You're right that the Good find on the code @Cellule. You're right, technically an inactive query won't be excluded if you're passing the query by name. To be totally honest though, I'm not entirely sure the case where a query can become inactive and participate in the refetch, mostly because as soon as an apollo-client/src/core/ObservableQuery.ts Lines 152 to 154 in d914d68
which calls apollo-client/src/core/ObservableQuery.ts Line 1057 in d914d68
which ultimately ends up removing that query from the list of queries (see line 1068): apollo-client/src/core/QueryManager.ts Lines 1049 to 1070 in d914d68
This apollo-client/src/core/QueryManager.ts Line 879 in d914d68
So theoretically is should only be active queries it can use since those are the only ones that should be available in that @maon-fp I tried your reproduction again and wasn't able to see the animals query fetched after the mutation. Each time I run the mutation, I'm seeing the warning about not being able to find a query that matches that document node. Is there something I'm missing here? I'd love to be wrong here and understand if there is a case where an inactive query can be refetched so we can update the docs accordingly. Let me know what I can do to see that fetch happen! |
I can guarantee there are inactive queries left in that list. |
I'm also seeing the same issue that inactive queries are getting refetched when just passing a |
After digging a bit deeper I realized that my queries are duplicate in |
I think what I'm seeing is #9903 |
Issue Description
In the docs it states:
But one can pass an arbitrary query to the
refetchQueries
and apollo client will query and cache the results.So either the docs are not correct or the client is "overfetching" not active queries.
Link to Reproduction
https://codesandbox.io/p/devbox/busy-maria-gjhpgz
Reproduction Steps
Go to the sandbox. Open the devtools. Add a person twice and you'll see the refetched animals in the console.
@apollo/client
version3.10.4
The text was updated successfully, but these errors were encountered: