apollo-client: Query refetched after a mutation doesn't trigger re-render
Seeing strange behavior where useQuery
hook doesn’t trigger re-render when the query is included inside useMutation
’s refetchQueries
array as an object with no variables.
For example, when I specify a query to be refetched after a mutation occurs like this:
refetchQueries: [{ query: DocumentNode }]
I am seeing the following results: mutation succeeds, refetch query happens, the cache is updated correctly but UI is not.
However, both refetchQueries: ['QueryName']
and refetchQueries: [DocumentNode]
work as expected.
Side note: the documentation for refetchQueries
array is inconsistent about the element type:
https://www.apollographql.com/docs/react/data/mutations/#refetching-queries
https://www.apollographql.com/docs/react/data/mutations/#refetchqueries
Versions System: OS: macOS 12.0.1 Binaries: Node: 16.8.0 Yarn: 1.22.15 npm: 8.0.0 Browsers: Chrome: 96.0.4664.110 Firefox: 85.0.2 Safari: 15.1
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Reactions: 8
- Comments: 16 (3 by maintainers)
As of 3.6.8 the issue is fixed for me. Thanks!
@jpvajda Looks like we’re at
3.6.9
right now. I upgraded to3.6.9
and can confirm thatrefetchQueries
is back working again. Thanks, I appreciate the follow up! 😃 👍🏻@KoenBrouwer Great news! Thanks for confirming.
I tried using both a list of strings and objects. Same result. With 3.6.2 no refetch occurs on any query. I’ll roll back to 3.5.10 for now.
I get the same with the following on 3.6.2, rolling back to 3.5.10 fixes the issue
Bump, I can confirm that this is the case using the (pseudo)code below using version
3.6.2
whereas this worked fine using version3.5.10
.Edit: actually, the actual query isn’t even triggered, and of course a re-render doesn’t happen as well. Maybe related to #9597?