Pagination

Pagination in the GraphQL API

The API implements a pagination mechanism based on the standard defined by graphql.org/learn/pagination. This system allows efficient navigation through large datasets.

Pagination Parameters

Each query that supports pagination includes the following fields:

first (integer, required)

  • Specifies the maximum number of results to return.

  • The value must be between 1 and 100.

  • If an invalid value is provided, an error will be returned.

after(string, optional)

  • Specifies a starting point for retrieving data.

  • This cursor is a unique string generated in the previous response.

  • If no cursor is provided, the query starts at the beginning of the available results.

How It Works

  • Without after: When the after field is not provided, the query returns the first available results, up to the limit defined by first. Example:

query {
  items(first: 1) {
   edges {
      cursor
      node {          
          externalId
      }
    }
    pageInfo {
        startCursor
        endCursor
        hasNextPage
        hasPreviousPage
    }
  }
}

Typical response:

  • With after: If a valid after cursor value is provided, the response will begin from the element corresponding to the cursor, including the subsequent elements up to the limit defined by first. Example:

Typical response:

Response Components

  • edges: A list of objects containing:

  • node: The data for an individual item.

  • cursor: The cursor associated with this item.

  • pageInfo: Metadata about the pagination:

  • startCursor: The first cursor of the current query.

  • endCursor: The last cursor of the current query.

  • hasNextPage: Indicates whether there are additional results beyond the current query.

  • hasPreviousPage: Indicates whether there are additional results before the current query

Best Practices

  • Always save the endCursor from the last response if you want to fetch the next set of data.

  • Use a first value that suits your needs to minimize server load and improve performance.

Last updated