question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Query doesn't return empty entries from cached array (offset pagination) any more

See original GitHub issue

We 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:open
  • Created 3 years ago
  • Reactions:1
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

3reactions
vigiecommented, May 4, 2021

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).

2reactions
transcranialcommented, Aug 12, 2020

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].

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found