Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

onCacheHit callback when query result is found in Apollo cache #320

Open
alessio-mms opened this issue Dec 1, 2021 · 3 comments
Open

onCacheHit callback when query result is found in Apollo cache #320

alessio-mms opened this issue Dec 1, 2021 · 3 comments
Labels
🪝 react hooks Feature requests related to React hooks

Comments

@alessio-mms
Copy link

The Problem

When using cache-first fetch policy I often require side-effects as result of querying data. The onCompleted callback generally addresses this problem, but only triggers when data is fetched from the server and not from cache. Currently, to address this problem, I need to implement a custom solution or change the fetch policy to cache-and-network, which obviously means we no longer gain the benefit from caching the data.

The Solution

Introduce an additional callback onCacheHit (Or something similar) that allows side-effects as a result of a query returning a result from cache.

Why is it better?

No custom solutions required for detecting Apollo client cache hits. This really would fix the headaches I get working with apollo client.

@alessio-mms alessio-mms changed the title onCacheHit callback when query result is found and returned from Apollo cache onCacheHit callback when query result is found in Apollo cache Dec 1, 2021
@jpvajda jpvajda added the project-apollo-client (legacy) LEGACY TAG DO NOT USE label May 25, 2022
@dbehmoaras
Copy link

dbehmoaras commented Jun 21, 2022

Any update on this? We are running into the same problem where we need to rely on the onCompleted callback which, as mentioned above, does not run when retrieving data from the cache. In our use case, we do not care about whether the result was retrieved from the cache or through a network call. We need to run the onCompleted callback in all cases or, as suggested here, provide an onCacheHit callback.

Frankly I'm a bit dismayed that Apollo decided that this should be the default behavior without exposing any kind of override.

@dbehmoaras
Copy link

dbehmoaras commented Jun 21, 2022

Following up to share that it appears that Apollo has pretty much flat out ignored this request since it has been an outstanding bug for YEARS. They just close the issue and do nothing. See below for just two of several examples:
apollographql/react-apollo#2177
apollographql/react-apollo#3488

@cfator
Copy link

cfator commented Dec 20, 2022

Also here scratching my head as to how something so fundamental has been purposely overlooked.

@jerelmiller jerelmiller added the 🪝 react hooks Feature requests related to React hooks label Apr 6, 2023
@jerelmiller jerelmiller removed the project-apollo-client (legacy) LEGACY TAG DO NOT USE label Jan 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪝 react hooks Feature requests related to React hooks
Projects
None yet
Development

No branches or pull requests

5 participants