GraphQL cursor pagination method

Overview

GraphQL cursor pagination is a method for paginating GraphQL APIs. In this context, a 'cursor' is a pointer that represents a specific position in the data set. Instead of saying "return page 3", you say "return 10 items after this cursor".

You can find more information about how this pagination method works in Shopify's API documentation.

The GraphQL cursor pagination method was developed for the Shopify GraphQL API; however, the same principles apply to other GraphQL systems.

GraphQL cursor options

Option
Summary

EndCursor path

The expected location of the pointer (i.e. the cursor) for the last item returned in the current page of results. When the next page is requested, the EndCursor is passed as the after argument, telling Shopify to start fetching from this point.

The EndCursor path is always defined in the following form: data.{type}.pageInfo.endCursor Here, the {type} element should be replaced with the type that's defined by the schema - for example:

data.products.pageInfo.endCursor

HasNextPage path

The expected location of the HasNextpage indicator. This is a boolean flag, indicating whether more pages exist after the current batch. If HasNextPage is false, then you’ve reached the end of the list, and no further requests are made.

The HasNextPage path is always defined in the following form:

data.{type}.pageInfo.hasNextPage Here, the {type} element should be replaced with the type that's defined by the schema - for example:

data.products.pageInfo.hasNextPage

GraphQL cursor pagination - endpoint body requirements

The GraphQL cursor pagination method works in conjunction with a query on the endpoint body, which determines required settings. For example:

{"query":"{products(first: 250, {{pagination_cursor}}) {edges { node { id title } } pageInfo { hasNextPage startCursor endCursor }}}","variables":{}}

If you need to change the existing query for an endpoint, you should edit the connector and access body options for the required endpoint.

When does pagination stop?

Pagination continues until hasNextPage is returned as false.

Last updated