endCursor parameter is missing in pageInfo in qraphql pagination

tahafarooqui
Tourist
8 0 2

I want save last cursor in database. endCursor is missing in pageinfo, Is there any alternative ?

There are only two parameters available. graphql Pagination 

        pageInfo {
          hasNextPage
        }

 

0 Likes
_JB
Shopify Staff
Shopify Staff
823 97 178

Hey @tahafarooqui,

 

There's no specific property for end cursor. In this case, you can save the cursor from the last object in the response when hasNextPage returns false.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

0 Likes
Andreas_Sch
Excursionist
16 0 0

Hi _JB,

this is breaking the GraphQl specification: https://relay.dev/graphql/connections.htm#sec-undefined.PageInfo

PageInfo must contain fields hasPreviousPage and hasNextPage, both of which return non‐null booleans. It must also contain fields startCursor and endCursor, both of which return non‐null opaque strings.

Also in the example it clearly states how to use it:  https://graphql.org/learn/pagination/ 
Please take a look at the bottom of the page.

Of course iterating over the response and use the last cursor is no issue, as long one codes the json parse logic by hand, but with tools expecting the endCursor field in the pageInfo this is a PITA. This breaks them every GraphQl client SDK supporting paging. I would expect this describes all of them.

Is there a way to report this as bug?

0 Likes
_JB
Shopify Staff
Shopify Staff
823 97 178

Hey @Andreas_Sch,

This is definitely an interesting point you raise, I'd like to bring this up with our product teams. Can you provide some examples of tools where pagination doesn't work with Shopify's GraphQL implementation? If you have any examples of specific methods/functions that expect the missing fields, please provide those as well.

JB | Developer Support @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

Andreas_Sch
Excursionist
16 0 0

Hi _JB,

thanks for reaching out!

I am currently developing in Python. There is only one library geared towards GraphQL I could find in Python, which is SGQLC.

It's main purpose is to create Python Classes based on the GraphQL schema. They are used to formulate queries, mutations, fragments and parse the JSON response into Python objects again.
Very similar to your Syrup library (at least that's the impression I got by a first glimpse into the Syrup Githup Repo).

SGQLC offers a method += to concatenate responses from cursor based paging. The method def __iadd__(self, other) in this source file implements it.
The line 374 in the current version is the breaking one: self.page_info.end_cursor = other.page_info.end_cursor

I am sorry, but I can't give you more examples. But this is the essential one for me.

0 Likes