Skip to main content

Pagination

Stitch provides comprehensive pagination capabilities via GraphQL. Most items, such as bank accounts, transactions and debit orders, can be paginated.

The default page size for collections is 500, but should you want to fetch a specific subset of records, pagination can help you with this.

The information returned for a query result is computed as a Connection, which is an object that contains Edges and Nodes.

  • Connection: Contains metadata about the paginated field. This is mostly used in cursor-based pagination because it gives us extra info we use to perform the next query.
  • Edges: Edges hold information about the parent and the child it contains. An edge connects two nodes, representing some kind of relationship between them. Each edge holds metadata about each object in the returned paginated result.
  • Nodes: Individual objects held in the edges.

Cursor-Based Pagination

Each collection response can return a PageInfo object that assists in cursor-based pagination. A cursor is a unique identifier for an item within a list and is usually base64 encoded. The cursor represents a connection between our data objects.

VariableTypePurpose
hasPreviousPagebooleanIndicates if there are results in the connection before the current page
hasNextPagebooleanIndicates if there are results in the connection after the current page
startCursorstringPoints to the cursor of the first node in the nodes list
endCursorstringPoints to the cursor of the last node in the nodes list

Forward Pagination

Forward pagination is achieved with the following connection variables:

VariableRequiredTypePurpose
firstyesintegerNumber of results to return per page
afternostringCursor to retrieve nodes after, should ideally be the endCursor of the previous page

The below example will fetch the first 10 payment request initiations, and also give a cursor object to indicate where the next page will begin.

So long as the value of hasNextPage is true, then you can continue requesting more records from the API, with the next page starting at the cursor value returned for endCursor.

Backward Pagination

Backward pagination is achieved with the following connection variables:

VariableRequiredTypePurpose
lastyesintegerNumber of results to return per page
beforenostringCursor to retrieve nodes before, should ideally be the startCursor of the previous page

The below example will fetch the last 100 payment initiations, and also give a cursor object to indicate where the previous page will begin. The records will be ordered in reverse chronological order by the date field, meaning the latest node will be first in the list of edges.

So long as the value of hasPreviousPage is true, then you can continue requesting more records from the API, with the next page starting at the cursor value returned for startCursor.

More Information

For further details on how to implement pagination for client requests, please refer to the GraphQl guide.