Query doesn't return empty entries from cached array (offset pagination) any more
See original GitHub issueWe noticed that our implementation of an offset/limit bases pagination broke. This used to work with earlier Apollo Client 3.0 versions (beta/rc) but doesn’t work in 3.0.2.
Intended outcome:
Custom type policies should be able to merge pagination results . useQuery
should return the array with the empty entries so that the component can find the data it needs to display a page based on an offset and limit.
Actual outcome:
The cache shows an array with empty entries. useQuery
returns the array with the empty items removed.
Apollo Client 3.0.2 React 16.13.1
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:13 (6 by maintainers)
Top Results From Across the Web
Advanced topics on caching in Apollo Client
This article describes special cases and considerations when using the Apollo Client cache. Bypassing the cache. Sometimes you shouldn't use the cache for...
Read more >Data not merging, Apollo 3 pagination with field policies
The query works but my cache is not updating or placing the data inside. import React from "react"; import { BrowserRouter as Router...
Read more >Laravel pagination not working with array instead of collection
I'm trying to paginate an array data set and it has proven more challenging ... All my queries just use the query builder...
Read more >@urql/exchange-graphcache | urql Documentation
A serialized GraphQL schema that is used by Graphcache to resolve partial data, interfaces, and enums. The schema also used to provide helpful...
Read more >Basics of Caching Data in GraphQL Apollo React Client
This is a playbook with the some of the common patterns on ... query doesn't return Apollo Client cannot return the data from...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @hwillson it is still a problem with latest. It would require an intentional update to reintroduce support for storing sparse arrays in Apollo cache. The current implementation uses a
filter
array operator that reduces a sparse array to a non-sparse array before storing.The downside to no longer supporting sparse arrays, as previously noted, is that it forces clients to pad their arrays with potentially millions of nulls before storing (imagine the case where only the first and thousandth page of data had been fetched, for example).
The provided offsetLimitPagination policy no longer works properly as it creates sparse arrays that are now automatically filtered:
[0, 1, 2, <3 empty items>, 6]
becomes[0, 1, 2, 6]
.