Skip to main content

Pagination

The Public API uses a cursor-based pagination system.

Each set of items, in this example cases, are wrapped in an items field, and each case is defined as an item in that items-field. This means the case is the item.

You can supply an amount variable, to limit the amount of items you get. It defaults to 100.

A cursor is returned for each item. This first and last cursor is also returned in the pageInfo field.

To aid in pagination, you can retrieve a totalCount and both a hasPreviousPage and a hasNextPage, indicating whether pagination in either direction is possible.

You can move forwards and backwards in the results by supplying a cursor to either the after or before variables.

The initial request looks like this. We only get 5 elements and are thus on the first page:

query getCases($amount: Int) {
cases(amount: $amount) {
items {
item {
id
name
}

cursor
}

totalCount

pageInfo {
hasPreviousPage
beforeCursor
hasNextPage
afterCursor
}
}
}

variables {
amount: 6
}

We get the elements with cursors, and page info:

{
"data": {
"cases": {
"items": [
{
"item": {},
"cursor": "1"
},
{
"item": {},
"cursor": "2"
},
{
"item": {},
"cursor": "3"
},
{
"item": {},
"cursor": "4"
},
{
"item": {},
"cursor": "5"
}
],
"totalCount": 123,
"pageInfo": {
"hasPreviousPage": false,
"beforeCursor": "1",
"hasNextPage": true,
"afterCursor": "5"
}
}
}
}

Variables

NametypeDescription
amountIntegerThe amount of items to return, defaults to 100
afterStringThe after variable gets the amount of items after the supplied cursor.
beforeStringThe before variable gets the amount of items before, or behind the supplied cursor.

You cannot supply both after and before. This will result in an error from the API

Example

The second request wants the next page and sends in the afterCursor as the after variable:

query getCases($amount: Int, $after: String) {
cases(amount: $amount, after: $after) {
items {
item {
id
name
}

cursor
}

totalCount

pageInfo {
hasPreviousPage
beforeCursor
hasNextPage
afterCursor
}
}
}

variables {
amount: 5,
after: "5",
}

This results in the second page being returned:

{
"data": {
"cases": {
"items": [
{
"item": {},
"cursor": "6"
},
{
"item": {},
"cursor": "7"
},
{
"item": {},
"cursor": "8"
},
{
"item": {},
"cursor": "9"
},
{
"item": {},
"cursor": "10"
}
],
"totalCount": 123,
"pageInfo": {
"hasPreviousPage": true,
"beforeCursor": "6",
"hasNextPage": true,
"afterCursor": "10"
}
}
}
}