Skip to main content

Pagination Using Rize's GraphQL API

Pagination helps manage large datasets by breaking them into smaller, manageable chunks. This guide provides examples of cursor-based pagination using Rize's GraphQL API.

Key Concepts

  • Edges: Contains the items in the current page.
  • Node: Represents an individual item in the dataset.
  • Cursor: A unique identifier for navigating between pages.
  • PageInfo: Metadata about pagination state, including:
    • hasNextPage: Indicates if there are more pages to fetch.
    • hasPreviousPage: Indicates if there are previous pages to fetch.
    • startCursor and endCursor: Markers for the beginning and end of the current page.

Example Queries

Fetch the First N Items

Query

query Projects($first: Int, $after: String) {
projects(first: $first, after: $after) {
edges {
node {
id
name
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}

Variables


{
"first": 2,
"after": null
}

Sample Response

{
"data": {
"projects": {
"edges": [
{
"node": {
"id": "1123124126",
"name": "Project ABC"
},
"cursor": "MQ"
},
{
"node": {
"id": "12434423422125",
"name": "Project XYZ1"
},
"cursor": "Mg"
}
],
"pageInfo": {
"hasNextPage": true,
"hasPreviousPage": false,
"startCursor": "MQ",
"endCursor": "Mg"
}
}
}
}

Fetch the Next Page

Use the endCursor from the previous response as the after parameter:

{
"first": 2,
"after": "Mg"
}

Fetch the Previous Page

Use the startCursor as the before parameter:

Query

query Projects($last: Int, $before: String) {
projects(last: $last, before: $before) {
edges {
node {
id
name
}
cursor
}
pageInfo {
hasNextPage
hasPreviousPage
startCursor
endCursor
}
}
}

Variables

{
"last": 2
"before": "Mg"
}

Error Handling

  • Invalid Cursor: Ensure the cursor value is valid and corresponds to an item in the dataset.
  • Missing Pagination Arguments: Always include either first/after or last/before.

Best Practices

  • Use first/after for forward pagination.
  • Use last/before for reverse pagination.
  • Always check pageInfo.hasNextPage or pageInfo.hasPreviousPage to determine if more pages are available.