Pagination & sorting
Pagination & sorting
Page through and order large lists of results.
Cursor-based pagination
List fields return Relay-style connections. Page forward with first + after, or backward with last + before, using the cursors returned in pageInfo.
first / afterReturn the first N items after a cursor (forward paging).last / beforeReturn the last N items before a cursor (backward paging).
paginatedIssues.graphql
query ListIssues($orgId: ID!, $first: Int!, $after: Cursor) {
organization(id: $orgId) {
issues(
first: $first
after: $after
orderBy: { field: CREATED_AT, direction: DESC }
) {
totalCount
edges {
cursor
node {
id
friendlyId
title
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
}Connection shape
Every connection exposes a list of edges, a pageInfo object, and a totalCount.
edges[].nodeThe item itself — request the fields you need inside node.edges[].cursorAn opaque cursor pointing at this item, used to page from here.pageInfo.hasNextPage / hasPreviousPageWhether more items exist in that direction.pageInfo.startCursor / endCursorPassendCursoras the next after value to fetch the following page.totalCountTotal number of items across all pages.
RESPONSE
{
"totalCount": 128,
"edges": [
{
"cursor": "Y3Vyc29yOjE5",
"node": { "id": "rprdbtyvc51ys7g7xq9xwra8cm", "friendlyId": 20, "title": "..." }
}
],
"pageInfo": {
"hasNextPage": true,
"endCursor": "Y3Vyc29yOjE5"
}
}Sorting
Pass an orderBy object with a field and a direction. The available fields depend on the connection.
orderBy.fieldThe field to sort by. For example,CREATED_AT.orderBy.directionASCfor ascending orDESCfor descending.
orderBy.graphql
issues(orderBy: { field: CREATED_AT, direction: DESC })