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.

`relayStylePagination` `read` method clobbers `pageInfo.startCursor` and `pageInfo.endCursor`

See original GitHub issue

Intended outcome: With a query as follows:

query {
  someConnectionField {
    edges {
      node {
        id
      }
    }
    pageInfo {
      hasNextPage
      endCursor
    }
  }
}

I would expect endCursor to be the value returned from the API, not "".

Actual outcome: Even though the API returns a valid cursor in endCursor, the relayStylePagination type policy attempts to read it from edges[0].cursor (or the last edge’s cursor) and completely replaces the one in `pageInfo.

These should default to pageInfo.{startCursor,endCursor} and not "". https://github.com/apollographql/apollo-client/blob/cefb3c32621de6973191c7abb6edd365d53cbf41/src/utilities/policies/pagination.ts#L101-L102

How to reproduce the issue: Perform a query as described above while using relayStylePagination.

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
dlqqqcommented, Jun 29, 2021

@benjamn Gave your PR a quick glance, it looks good to me. Glad it was (relatively) easy! I was just about to submit a PR earlier, but you beat me to it 😅 . TYSM!

2reactions
benjamncommented, Jun 28, 2021

@migueloller @diracs-delta @meliborn Please have a look at this PR and let me know if it meets your expectations: #8438

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cursor-based pagination - Apollo GraphQL Docs
With this approach, the requested cursor ID should not appear in the new page, since it identifies the item just before the beginning...
Read more >
graphql – CSS-Tricks
pageInfo object that provides: endCursor – cursor of the last item in posts.edges ,; startCursor – cursor of the first item in posts.edges ......
Read more >
Apollo Client relayStylePagination doesn't paginate data ...
I've implemented a TableWithData component that creates a Table after fetching the data using a relayStylePagination logic
Read more >
Less code for relay style paginations in Apollo and React.
I also know some people who use Relay style pagination, ... Put the new comments at the end of the list and update...
Read more >
GraphQL Pagination with Apollo V3 - Part 2
Our return data consists of pageInfo containing the data for the endCursor ... In the render method, we map the edges containing the...
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