mateusz.kwiecinski
05/28/2024, 9:27 AMerrors
array)
With such setup, I see the request that makes network call returns the partial data, but I'm unable to access cached data via a fetchPolicy(FetchPolicy.CacheOnly)
request.
Couple of highlights of the setup:
• storePartialResponses
is enabled
• emitCacheMisses
is enabled
• custom CacheKeyResolver
is provided that computes list of IDs using listOfCacheKeysForField
, similar to the one mentioned in the documentation
example schema:
type Viewer {
id: String!,
books(ids: [String!]!): [Book!]!
}
type Book {
id: String!
name: String!
}
Full repro with failing test can be found here. The only workaround I was able to come up with is not to compute listOfCacheKeysForField
, but that disables the neat feature introduced in (I think?) 3.x we rely on to access individual element details without making extra network calls.
So in the end I wonder if I can expect the partial data to be accessible after it was fetched, or due to the fact apollo knows it's partial it is not considered "valid"?mbonnin
05/28/2024, 12:24 PMmbonnin
05/28/2024, 12:25 PMdata == null
for the whole responsembonnin
05/28/2024, 12:29 PMmateusz.kwiecinski
05/28/2024, 12:35 PMI think what you’re looking for is partial cache results?I wouldn't say that, I think. I don't necessarily need any partial result, I'd say I only want to read the latest data saved in the cache.
the cache stops at the first cache miss and returnsThis is the behavior I observe when I usedata == null
listOfCacheKeysForField
, returning null
there, allows me to read the partial/incomplete data that has just been written to the cache. So apollo has already the capability to return the data I need
It feels like
• using listOfCacheKeysForField
- always computes the required response and fails due to cache miss, ignoring saved cache keys
• not using listOfCacheKeysForField
- checks if the root key exists in cache and returns associated data
so what I'd say what I'm missing is a mechanism that tries to recover from a "computed" cache miss by checking if a "stored" key is present in the cache (which I hope is much simpler than fully fledged partial cache results 😅_)_mbonnin
05/28/2024, 12:37 PMbook-id-invalid
stored in cache:
"book-id-1" : {
"id" : book-id-1
"name" : book-name-1
}
"viewerId" : {
"id" : viewerId
"books({"ids":["book-id-1","book-id-invalid"]})" : [
CacheKey(book-id-1)
]
}
"QUERY_ROOT" : {
"viewer" : CacheKey(viewerId)
}
But in other scenarios, you would have it, right?mbonnin
05/28/2024, 12:40 PMmateusz.kwiecinski
05/28/2024, 12:40 PMmbonnin
05/28/2024, 12:41 PMmbonnin
05/28/2024, 12:41 PMlistOfCacheKeysForField
tries to read book-id-invalid
and throw a cache miss therembonnin
05/28/2024, 12:41 PMmbonnin
05/28/2024, 12:41 PMmateusz.kwiecinski
05/28/2024, 12:42 PMmateusz.kwiecinski
05/28/2024, 12:43 PMmbonnin
05/28/2024, 12:50 PMmbonnin
05/28/2024, 12:51 PMids
argumentmbonnin
05/28/2024, 12:53 PMids
arguments first and then fallback to the existing list if there a cache miss)mateusz.kwiecinski
05/28/2024, 12:58 PMmateusz.kwiecinski
05/28/2024, 1:00 PMmateusz.kwiecinski
05/28/2024, 1:01 PM