PageInfo
Information about pagination in a connection.
Type Definition
type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}Fields
| Field | Type | Nullability | Description | Relationship |
|---|---|---|---|---|
| hasNextPage | Boolean | Non-null | Indicates if there are more pages to fetch. | Scalar |
| hasPreviousPage | Boolean | Non-null | Indicates if there are previous pages to go back to. | Scalar |
| startCursor | String | Nullable | The cursor corresponding to the first node in the edges list. | Scalar |
| endCursor | String | Nullable | The cursor corresponding to the last node in the edges list. | Scalar |
Relationships
The PageInfo type is used to provide pagination metadata for connection objects. It does not directly relate to other object types but is embedded within connection types such as:
PreviousPriceConnection.pageInfoProductConnection.pageInfo
These connections use PageInfo to inform clients about the pagination state, enabling efficient traversal of paged data sets.
Usage Examples
Basic Query
{
productConnection(first: 5) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
node {
id
title
}
}
}
}Field Selection
{
previousPriceConnection(last: 10) {
pageInfo {
hasNextPage
startCursor
}
edges {
node {
price
effectiveDate
}
}
}
}Nested Queries
{
productConnection(first: 3) {
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
edges {
cursor
node {
id
title
previousPriceConnection(last: 2) {
pageInfo {
hasNextPage
endCursor
}
edges {
node {
price
effectiveDate
}
}
}
}
}
}
}Filtering and Sorting
The PageInfo object itself does not support filtering or sorting, but it is used alongside connection queries that do. For example, to paginate through products sorted by creation date:
{
productConnection(first: 5, sortKey: CREATED_AT, reverse: true) {
pageInfo {
hasNextPage
endCursor
}
edges {
cursor
node {
id
title
createdAt
}
}
}
}To fetch the next page using the cursor:
{
productConnection(first: 5, after: "cursor-value") {
pageInfo {
hasNextPage
endCursor
}
edges {
cursor
node {
id
title
}
}
}
}Implements
The PageInfo type does not implement any interfaces.
Connections
PageInfo is a subfield of connection types that follow the Relay Cursor Connections Specification, providing pagination metadata for:
PreviousPriceConnectionProductConnection
These connections contain edges and pageInfo fields to enable cursor-based pagination.
Related Types
Boolean!— The non-nullable scalar type used forhasNextPageandhasPreviousPage.String— The scalar type used for cursor fieldsstartCursorandendCursor.
Best Practices
- Always request
pageInfowhen querying connection fields to handle pagination effectively. - Use
hasNextPageandhasPreviousPageto determine if additional pages exist before making further requests. - Use
startCursorandendCursorto paginate forward or backward through results usingafterandbeforearguments. - Limit the number of items per page to optimize performance and reduce payload size.
- Combine pagination with sorting and filtering on connection queries for efficient data retrieval.
Notes
- The
PageInfoobject provides essential information for cursor-based pagination but does not itself support filtering or sorting. - Cursors (
startCursorandendCursor) are opaque strings that should be treated as tokens for pagination and not parsed or modified. - Pagination using
PageInfohelps improve API performance by enabling incremental data fetching. - The API currently requires no authentication; however, this may change in future versions. Always handle errors gracefully in your client applications.