-
Notifications
You must be signed in to change notification settings - Fork 7
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
Revisit refetchQueries
API
#419
Comments
Honestly just better documentation on it would be the useful thing - perhaps an example showing an off-screen/unmounted and an on-screen/mounted container. Revalidate them both, but see the network request fire only for the second? Because the behaviour as-is is technically a feature, right? Why refetch data for things that aren't shown? Or is it that unmounted queries are not marked as invalid (ie when re-mounted they're not also refetched) which would understandably cause friction (because you'd always have to refresh on remount)? Perhaps there should be an option to
I don't know enough about the fetching mechanisms to understand if a fourth option |
@thclark I do agree that documentation could be improved, though long-term I'd like to get away from the document-based thinking here if at all possible. There are too many footguns with the existing API that make it difficult to do the right thing. For example, its too easy to add a new query somewhere in your app that might be changed by a mutation and forget to add that query to the list of "refetch queries" for that mutation. The other issue is that the way we currently store values in Apollo Client internals doesn't allow for us to do anything with "inactive" queries. Inactive queries are actually removed from the internal data store once they become inactive, which then become garbage collected. To allow for something like a What I'd like to pursue instead is some kind of field-based invalidation API where rather than using queries themselves to force refetches, you can mark a field in the cache as stale which would force any queries dependent on that field to be refetched. If a query is active at that time, it would be refetched immediately. If the query is "inactive", then we'd refetch that query as soon as the query mounts. I believe this would scale a bit better than our current solution. Long-term I'd love for this to replace Regardless, even if we keep Sorry for the brain dump, but hope this helps describe where my head is at! |
The
refetchQueries
API used primarily to refetch data after a mutation is a bit unintuitive in its current form. We've had quite a few questions about this feature where people misunderstand how it works.The key part of this API primarily misunderstood is that
refetchQueries
only refetches active queries, which are queries that are currently mounted on screen. Once a query has been unmounted/unsubscribed, it will no longer be refetched. This presents a lot of confusion when devs think a bug exists because they don't see the network request after the mutation.As such, I'd like to revisit this API in future major and see what we can do to improve this to make the behavior more intuitive.
The text was updated successfully, but these errors were encountered: