Hey,
So I have a table with offset / limit pagination. I have a custom merge and read function purposed for my needs.
There is a particular scenario I’m trying to understand how does Apollo client handle it and what I could potentially do to maintain some of the data, what I mean:
- Let’s say I navigate to the second page of my table with a limit of 10 items which I have fetched using fetchMore method from useQuery. Now my cache has 20 items and my read function properly slices the data to show me what I want offset = 10 and limit 10.
- Now while on this second page I decide to remove an item and in this mutation I have both an update function and refetchQueries array. My update function properly removes the data from the cache leaving me with 19 items in my cache out of a total of let’s say 30 but I have not yet fetched the rest of these thus they are not in my cache. Because I have another 10 items left and I don’t know what this data is I thus use my refetchQueries array to get this missing data from the server to update my UI with this new item since my limit is still at 10. So far so good this all works fine.
- What I’m noticing however is in my cache the first 10 items are now null, the reference to these have been. lost I believe this is possibly due to the refetch array which only refetches based on the input of offset = 10 and limit 10. I can see that in my custom merge function the existing data after the refetch is undefined.
My question is how can I maintain these first 10 items based on my scenario? I’m trying to figure out if this is possible, if so, how?
My one thought is I can update my refetchQuery to account for where I am on my page and refetch all of that data and that before which would populate my cache properly. But this doesn’t seem practical as if I have like 1k items and I’m on page 80 I would then run a query to get all 799 previous data set. This example is on a small scale but you can see my point with extremely large data set this is not practical at all and becomes an expensive query.
Is there a way to refetch the query server side but ensure it does not overwrite my cache setting it to null. I’m trying to determine if it’s something I’m doing wrong as I expected Apollo to just update the offset = 10 and limit 10 data set and not affect the previous data set of offset = 0 and limit 10. Thanks for any feedback.