Stitch API

5.7. Pagination

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

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: Contains the info about the parent and the child it contains. It connects two nodes, representing some kind of relationship between the two nodes. 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 for more records for 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 for more records for 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.