-
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
There is no way to mark queries as "needs to be refetched" using the apollo client instance. #7878
Comments
@omerman This is one of the goals of #7819 and #7827 in the next minor version of Apollo Client (v3.4). However, I should warn you that I'm still working through some issues around calling |
@benjamn I understand from these issues that there is work in progress regarding the abilities of the cache using the client instance, and also that you don't have the complete story.. But I couldn't quite understand how I have a use case where my server has implemented graphql queries, but there are no mutations implemented, all of the updates are implemented via rest api.. |
@omerman I think you've convinced me that the client.reobserveQueries(
// This callback invalidates some fields in the cache.
cache => {
cache.modify({
someField(value, { INVALIDATE }) {
return INVALIDATE;
},
});
},
// This callback gets called for any ObservableQuery objects affected by the invalidation.
(observableQuery, diff) => {
// Force any affected queries to be refetched from the network.
return observableQuery.refetch();
},
); Would that be useful to you? |
@benjamn If I understand it correctly, it would be useful :), I have a few clarifications/questions:
Let me know what you think |
@omerman I believe #8000 will implement what I described above, incorporating your feedback about the optionality of the Note that this new 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 I welcome any feedback you have on #8000, as it is still very much subject to change/improvement! |
@benjamn Looks great! If I'll think of any more feedback Ill let you know :) |
I still don't understand how can I cause a query to refetch when it's not currently active.. I'm clueless by something that should be really easy in my opinion... |
@amitozalvo There's a separate issue open for that: #7060 |
Thanks all - it looks like this particular issue is resolved. Per @dylanwulf's comment, let's use #7060 for further discussion 🙏🏻 |
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 itcache.modify()
)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
The text was updated successfully, but these errors were encountered: