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

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

Open
cyberwombat opened this issue May 17, 2020 · 3 comments
Open

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

cyberwombat opened this issue May 17, 2020 · 3 comments

Comments

@cyberwombat
Copy link

Reopening issue filed in #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.

@hatchli
Copy link

hatchli commented Jun 3, 2020

Is there any word on this?

@rmlevangelio
Copy link

+1. Any workaround available?

@cubogdan
Copy link

cubogdan commented Jun 15, 2020

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

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

4 participants