react-apollo
react-apollo copied to clipboard
Query.onCompleted isn't fired after fetching data from the cache
Reopening issue filed in https://github.com/apollographql/react-apollo/issues/2177 since that was closed without a fix. Issue is still present in 3.1.3.
Summary of issue: onCompleted is not fired if the same data is attempted to be fetched again right after initial fetch. For example: (A and B would be useLazyQuery calls)
Fetch A - onCompleted is fired Fetch B - onCompleted is fired Fetch A - onCompleted is fired Fetch A again - onCompleted is NOT fired
Perhaps related to this explicit blocking: https://github.com/apollographql/apollo-client/blob/master/src/react/data/QueryData.ts#L272 ?
Only solution right now is to bypass/disable cache.
Is there any word on this?
+1. Any workaround available?
Adding fetchPolicy: "cache-and-network" to the Query makes it work, but it never fetches from cache in my case.
This is not a fix, it's an accidental hack.
Simple example:
const [fetchUsers, { loading }] = useLazyQuery(GET_USERS_PAGINATED, {
fetchPolicy: "cache-and-network",
variables: {
pageSize: PAGE_SIZE,
},
onCompleted: (data) => {
// ...
},
}