Apollo Client version: 2.6.4
, client built in React, using hooks.
I was hoping that I could use a refetch
(returned from useQuery
) to pull only from the cache, but from debugging and looking through the code (https://github.com/apollographql/apollo-client/blob/c44e8211268e808106e81da7665f65f81fac2baf/packages/apollo-client/src/core/ObservableQuery.ts#L307) it seems like the fetchpolicy favours network calls?
Here's the reason I want to allow pulling from the cache only in a refetch:
The query organization
has a field for a list of users (of type User
).
The client (React) calls the mutation addUser
which has a return type Organization
This response from the mutation already updates the cache of the organization with the new list of users.
refetch
is called (in the useQuery
hook) so that the Component that renders the list is updated with the new user. The user is already in the cache, the mutation response updated it, and I see that it is complete
in debugging. Yet it still does a network call.
Perhaps I've misunderstood the point of refetch
(I want my useQuery
hook to return new data to re-render the component) - or perhaps there is a way to have the refetch honor the cache? Please help
Shouldn't the query be updated automatically if its data in the cache is updated, because it's observable?
If the user wants to refresh data, it should force to get recent data to the user, not from the caches. The subscription design with the caches and updating is fine but we need to network-only
for the refetch.
any update on this? @benjamn
Most helpful comment
If the user wants to refresh data, it should force to get recent data to the user, not from the caches. The subscription design with the caches and updating is fine but we need to
network-only
for the refetch.