Skip to content
This repository has been archived by the owner on Apr 13, 2023. It is now read-only.

refetch from query returns data from cache instead of new data #3457

Closed
anmolchandra96 opened this issue Sep 5, 2019 · 4 comments
Closed

Comments

@anmolchandra96
Copy link

anmolchandra96 commented Sep 5, 2019

The refetch function when executed returns a promise which resolves with the data from the cache instead of data from the re-run query.

Example:

<Query query={SAMPLE_QUERY} fetchPolicy="cache-and-network"> { ({ refetch }) => <ChildComponent refetchParent={refetch} /> } </Query>

In the case above whenever I execute the refetchParent function I get a promise which resolves with the value from the data in the cache instead of the data from the re-run query.

My requirements force me to set the base query fetch policy as cache-and-network but I want to make sure when refetch function is executed I get data from the re-run query instead of data from the cache.

Any help on the issue would be greatly appreciated.

@hwillson
Copy link
Member

hwillson commented Sep 6, 2019

Issues here are reserved for React Apollo bugs. You’ll have a much better chance of getting this answered in Apollo’s Spectrum community or on Stack Overflow. Thanks!

@hwillson hwillson closed this as completed Sep 6, 2019
@mptorz
Copy link

mptorz commented Sep 9, 2019

@anmolchandra96 I am in the exactly the same situation. We also have to use "cache-and-network" and we have an identical problem, so please let me know how you resolved it!

@derek-duncan
Copy link

This is related to this change in apollo-client apollographql/apollo-client#4840

@slorber
Copy link

slorber commented Nov 20, 2019

same here, I can see the refetch is being done, but there's no way I can do await refetch() because it resolves immediately with cache data. I need to be able to know when the actual network refetch has completed

Yes I don't necessarily want to remove "cache and network" in my original query. Being able to provide refetch options could be useful.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants