Hi,
const getBookmarks = graphql(BookmarkedViewQuery, {
options: ( props ) => {
return {
fetchPolicy: 'network-only', // skip the cache
}
} ,
});
After a mutation it seems like:
componentWillReceiveProps(nextProps) {
// console.log("refresh");
this.props.data.refetch();
}
will return cached data
Let's see if https://github.com/apollographql/react-apollo/pull/1901 fixes the issue when it is released. Could you create a small reproduction as well?
I have the same problem. Sometimes props.refetch return cached data to a child component.
This should no longer be an issue using a recent version of Apollo Client / React Apollo. Closing for now, but if anyone is still encountering this, please let us know (ideally with a small runnable reproduction). Thanks!
@hwillson This still happens to me in the latest version. It's pretty particular because it doesn't always happen but under certain conditions. It's pretty hard to isolate, but think it might be related to refetching two or more components at the same time.
I wrapped the call in a timeout, and the updated data was passed to the component:
setTimeout(() => {
this.props.refetch();
}, 0);
In my Network tab, this query is no longer being batched with the rest. I assume because it's deferred. I disabled batching by just using apollo-link-http
(instead of apollo-link-batch-http
), but it kept happening. So I don't think this is directly related to batching, but I'm not sure how Apollo works internally.
Hope that helps.
I can see the call being made to the server but logging in the client shows the same data as the previous call. Too many layers to make a small repro yet but it does seem to be happening still.
It could be because I have the same input variables as the previous call? Its a time based event though so it should actually refetch and return the new result.
the refetch function called follows the fecthPolicy of its query function. If the fetchPolicy is set to cache-and-network refetch gets the data from the cache and returns it while simultaneously making a network call and subsequently sets the new data in the cache.
Is there a way for me to keep the fetchPolicy in the query as cache-and-network but make sure that refetch returns the data from the network call instead of from cache
This is still an issue in fully updated versions, can we reopen this issue?
I think this is really important feature, usually you don't want to use "network-only" to prevent irrational network calls, but in 90% cases if user want to refetch a data, you want to show him a loader/spinner which will be hidden once refetch was complete, not instantly after it was shown.
Most helpful comment
This is still an issue in fully updated versions, can we reopen this issue?