Skip to main content

Pagination

To implement pagination we make use of the pageInfo: PageInfo property:

type PageInfo {
hasNextPage: Boolean!
hasPreviousPage: Boolean!
startCursor: String
endCursor: String
}

Where hasNextPage and hasPreviousPage will tell us wether there is a next or previous page or we hit the last or first one respectively.

On the other hand, startCursor and endCursor will give us cursor values for the start and end of the collection retrieved. These can be used as the after or before parameter in subsequent queries.

Example - getting paginated projects‚Äč

We run the following query:

query firstPage {
me {
accounts(first: 1) {
nodes {
projects(first: 3) {
pageInfo {
hasNextPage
endCursor
}
nodes {
name
}
}
}
}
}
}
Show example response Show cURL example Try in explorer

We can then get the second page with the query:

query secondPage {
me {
accounts(first: 1) {
nodes {
projects(first: 3, after: "Mw") {
pageInfo {
hasNextPage
endCursor
}
nodes {
name
}
}
}
}
}
}
Show example response Show cURL example Try in explorer