Was this helpful?

Pagination using Cursor Connections

For consistency, the Alpaca API uses the GraphQL Cursor Connections Specification to control pagination. This is also known as implementing "Cursor-based Pagination".

Alpaca have adopted the GraphQL Cursor Connections Specification following the aim of providing best practices in GraphQL. As a summary, the technique provides a consistent approach to pagination so that it can be standardised across queries. This also allows you to leverage existing pagination techniques of libraries supporting cursor connections (such as relay or apollo or other client libraries).


Slicing is done by using the first argument, and pagination is done by providing the after argument

Opposed to using limit/offset values, you will instead provide first with the number of values you want, and after to contain the cursor of the edge that you obtain records after.

1# Example query illustrating the response structure of a cursor connection
3query CollectionItemsUsingCursorConnections {
4  # An query that provides a cursor connection response
5  collectionItems(
6    # Example query constraints
7    collectionIds: ["collection/ABC123"]
8    # First controls the slicing, returning 10 connection items
9    first: 10
10    # After controls the paging. Provide the cursor of the last edge to paginate
11    # after that edge. If you don't send a cursor, the first results are
12    # returned
13    after: "opaqueCursor"
14  ) {
15    edges {
16      cursor
17      node {
18        id
19        title
20      }
21    }
22    pageInfo {
23      hasNextPage
24    }
25  }

Sandbox: Configure | Try Operation

  • Slicing is done by providing the first argument to collectionItems. This asks the connection to return 10 collection items

  • Pagination is done by providing the after argument to collectionItems. We provided a value of for the cursor so we should load collection items after that cursor

  • For each edge, we asked for a cursor. This cursor is an opaque string, and is precisely what we would pass to the after argument to paginate after this edge.

  • We asked for hasNextPage, which will tell us whether there are more edges available.

Note: Each cursor connection the API implements can offer different edge data, as well as offer other response type data, such as totalCount or pageInfo.endCursor.


How do I jump to a specific page

We currently do not support jumping to a specific page using Cursor Connections.


Copyright © 2023 - Made with love ❤️ in Australia.