0

Heyaa...

I'm kind of a newbie in configuring Apollo cache for handling paginations, thus I'm facing this issue...

Currently, I'm successfully added some field policies to my InMemoryCache options, able to smoothly paginate data. But, it all turns bad when some other query calls happen which mutate and update the cache (maybe?). When all is done, I can see in Apollo devtool that the cache's data is perfectly correct, but the data that is returned from the useQuery hook is not the same (it takes the data that is returned from the network request only, rather than the one that is combined with cached data).

I console log the data that is coming from the cache's read function:

########## FIELD READ ##########
RETURN (27) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

which is correct, it should have all the combined data, resulting in 27 items.

but from the hook's side and eventually being rendered:

########## RENDER ##########
entries (9) [{…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}, {…}]

it only returns the latest 9 items coming from the network request.

Could anyone help to explain how it works and what might cause this? Thanks heaps!

for context, the hook's options that I use:

...
fetchPolicy: "cache-and-network",
nextFetchPolicy: "cache-first",

I've tried various things to configure the cache, customizing its keyFields, keyArgs, merge, and read functions but with no success. I also tried with cache-first fetchPolicy but also no success.

The useQuery hook should return the same data as the cache read policy.

0 Answers0