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.

Pagination with relayStylePagination - how to use ALL keyArgs?

See original GitHub issue

Hi. I have multiple queries with a long list of arguments that I am using for filtering items.

Apollo Cache works perfectly well without pagination: each list of items cached separately to each set of arguments (filters) and on UI I can always see the proper list of items.

When I have added relayStylePagination() to InMemoryCache this behavior was broken. If I understand the reason correctly it’s because of the default keyArgs: false for relayStylePagination().

The question: is it possible to force relayStylePagination() behave the same as it was by default without pagination? I mean that relayStylePagination() will get in count all the arguments and separate cached lists with different sets of arguments.

Alternatively, I can path all my arguments to relayStylePagination(), but this will be ugly and hard to support.

const cache = new InMemoryCache({
  typePolicies: {
    User: {
      fields: {
        models: relayStylePagination([longListOfCustomAndChangingArgumensShouldBeHere]),
        animals: relayStylePagination([longListOfCustomAndChangingArgumensShouldBeHere]),
        locations: relayStylePagination([longListOfCustomAndChangingArgumensShouldBeHere])
      }
    },
  },
})

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
benjamncommented, May 14, 2021

Yep that should work!

Another trick for excluding object properties is to use object ...rest notation:

const { first, after, ...rest } = args || {};
return Object.keys(rest).sort();
0reactions
hwillsoncommented, May 27, 2021

Sounds like this has been solved. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Key arguments in Apollo Client - Apollo GraphQL Docs
A keyArgs array can include the types of values shown below. The storage key for a cached field uses the values of all...
Read more >
Confusing pagination result with keyArgs in FieldPolicy #6537
When I use default keyArgs ['filter', 'sort'] , the pagination works as expected. ... In principle, read and merge functions can take full...
Read more >
React Apollo Client - query results mixing up in cache
We have to pass keyArgs explictly when relayStylePagination or similar pagination is used. A keyArgs: ["type"] field policy configuration ...
Read more >
Pagination – Angular - GraphQL Code Generator
Apollo Client provides an offsetLimitPagination helper function that you can use to generate a field policy for every relevant list field.
Read more >
Pagination | GraphQL
A common use case in GraphQL is traversing the relationship between sets of objects ... to get a list of R2-D2's friends, we...
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