Paginate Your Results

GraphQL queries can return up to 2000 records. By default, the wire adapter returns the first 10 results and you can request subsequent pages using the cursor information. The GraphQL API and graphql wire adapter use the GraphQL Cursor Connections Specification for pagination of all data collections they return.

To specify the number of records to return, use the first argument. The default number is 10. If hasNextPage is true, you can provide the endCursor value to the after argument of a subsequent query, which requests the next page of results.

Backward pagination using last and before isn’t currently supported.

Here’s a basic query with cursor information.

This example response contains cursor information.

Requesting totalCount can have performance implications for large or complex queries.

In this example, we create a simplePagination component with a reset button and a next page button. The reset button resets the pagination. The next page button pages through the results. The component displays 5 results on each page by default. It uses an isLastPage property to determine if the next page button is disabled.

The graphqlPagination component in the lwc-recipes repo gets contact data with pagination to navigate through the list.

The component uses the lightning-button base component to display the reset button and next page button. It displays the account name and annual revenue in the lightning-card base component.

When clicked, the next page button sets the lastCursor value to the endCursor value and displays the next set of results.

Paginate Results

Feature Limitations of Offline GraphQL