How to Query Paginated Data in GraphQL
The Profile GraphQL API uses Relay-style cursor-based connections to support efficient and flexible querying of large lists like Transactions.
Relay-style connections are similar to basic cursor-based pagination, but have a slightly different response structure:
countreturns the total number of items in the list.edgesreturns an array ofcursorandnodeobjects, where eachnodeis an item in the list.pageInforeturns an object containing pagination metadata, includingstartCursor,endCursor,hasPreviousPageandhasNextPagefields to help paginate subsequent queries.
Link to this section#Examples
Link to this section#Paginating a Profile's Transactions
We can construct a query to return the first page of the Profile's Transactions:
The response will return all Transaction nodes with cursors from ABC to DEF.
Now to get the next page, we repeat this query, setting the value of after to the ending cursor from the response: pageInfo.endCursor.
Once pageInfo.hasNextPage returns false, we've pulled down all the available transactions.
Link to this section#Using Pagination with React + Apollo
In this example, we use the React Apollo Client to create a TransactionsList React component that renders a paginated list of the user's transactions.