question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

There is no way to mark queries as "needs to be refetched" using the apollo client instance.

See original GitHub issue

Having 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

  1. mark certain queries as invalid(That’s actually something we can do using cache.modify())
  2. 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:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
omermancommented, Apr 17, 2021

@benjamn Looks great! If I’ll think of any more feedback Ill let you know 😃

2reactions
benjamncommented, Apr 16, 2021

@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 to observableQuery.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 the ObservableQuery 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!

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found