react-apollo icon indicating copy to clipboard operation
react-apollo copied to clipboard

Query.onCompleted isn't fired after fetching data from the cache

Open cyberwombat opened this issue 5 years ago • 3 comments

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.

cyberwombat avatar May 17 '20 06:05 cyberwombat

Is there any word on this?

hatchli avatar Jun 03 '20 13:06 hatchli

+1. Any workaround available?

rmlevangelio avatar Jun 08 '20 03:06 rmlevangelio

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) => {
      // ...
    },
}

cubogdan avatar Jun 15 '20 11:06 cubogdan