There is no way to mark queries as "needs to be refetched" using the apollo client instance.
See original GitHub issueHaving React’s useMutation({...update, refetchQueries, reobserve...})
is great, really, but I think it’s a big flawed that we can’t use apollo client raw instance and tell it
- mark certain queries as invalid(That’s actually something we can do using
cache.modify()
) - next time those queries are observed, refetch them or… 2.1 if they are being observed at the moment, refetch them now…
I know that we can use the useMutation
and tell each mutation how to behave…
But sometimes we just want to be able to tell apollo client to mark some quereies as “needs a refetch” outside the context of react and I think that we should be able to do so
Looking forward for your response, Thank you again for your great work
Issue Analytics
- State:
- Created 3 years ago
- Reactions:2
- Comments:9 (5 by maintainers)
Top Results From Across the Web
Refetching queries in Apollo Client - Apollo GraphQL Docs
When onQueryUpdated is provided, it can dynamically decide whether (and how) each query should be refetched. Returning false from onQueryUpdated prevents the ...
Read more >When To Use Refetch Queries in Apollo Client
In this post, I'll explain when it makes sense to use refetchQueries , and when you should rely on Apollo Client's automatic cache ......
Read more >Advanced topics on caching in Apollo Client
To accomplish this, call client.resetStore . This method is asynchronous, because it also refetches any of your active queries.
Read more >Queries - Apollo GraphQL Docs
This article shows how to fetch GraphQL data in React with the useQuery hook and ... When loading is false and there is...
Read more >How to use Apollo Client with Remix - Apollo GraphQL Blog
It's both a server and browser runtime, which means you can render ... refetching queries unnecessarily, and it also enables you to use...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@benjamn Looks great! If I’ll think of any more feedback Ill let you know 😃
@omerman I believe https://github.com/apollographql/apollo-client/pull/8000 will implement what I described above, incorporating your feedback about the optionality of the
onQueryUpdated
callback (defaulting toobservableQuery.refetch()
).Note that this new
client.refetchQueries
API takes named options (updateCache
,include
,onQueryUpdated
) rather than positional arguments, which makes it easier to mix and match the options, I think.Unfortunately I don’t have a great answer yet for your use case of queueing up refetch requests for unmounted/hidden components, but that’s definitely something we want to support. I think it will require allowing the
ObservableQuery
to outlive the React component, while also keeping track of whether the component is currently mounted/visible, so we can fire pending refetches when the component is remounted. That kind of functionality (keeping the query alive when the component is unmounted) makes sense for lots of reasons, I think, but theObservableQuery
class doesn’t currently have a mode of being unmounted (as far as React is concerned) but still listening for cache updates.I welcome any feedback you have on #8000, as it is still very much subject to change/improvement!