GraphQL cursor pagination method

Overview

GraphQL cursor pagination is a method for paginating GraphQL APIs.

Here, we send a GraphQL query requesting a list of items. This query includes parameters such as the number of items to fetch and any filtering or sorting criteria required. In response, requested items are received, together with cursor information (each item in the response is associated with a cursor, which is typically a unique identifier for that item).

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

GraphQL cursor options

OptionSummary

EndCursor path

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

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