Overview
ThegraphqlPagination component demonstrates cursor-based pagination with GraphQL queries. It uses the pageInfo object to navigate through result sets and track pagination state.
Source
force-app/main/default/lwc/graphqlPagination
Key Features
- Cursor-based pagination with
afterparameter - PageInfo metadata for navigation
- Total count tracking
- Previous/next page detection
- Reactive variable updates
GraphQL Pagination Query
Pagination Parameters
first
Specifies the number of records to retrieve per page:after
Cursor pointing to the position after which to start fetching records:PageInfo Object
ThepageInfo object provides pagination metadata:
endCursor: Cursor position at the end of the current pagehasNextPage: Boolean indicating if more records existhasPreviousPage: Boolean indicating if previous records exist
Total Count
Request the total number of records matching the query:totalCount can have performance implications for large and/or complex queries. Use with caution.
Reactive Variables Pattern
Provide pagination variables through a getter:Navigation Handlers
Next Page
Update the cursor to the end of the current page:Reset to First Page
Clear the cursor to return to the beginning:Page State Getters
Determine navigation state based on pageInfo:Pagination Controls
Disable navigation buttons based on page state:Pagination Pattern Summary
- Define
afterandpageSizevariables - Request
pageInfoand optionallytotalCount - Use
endCursorto navigate to the next page - Check
hasNextPageandhasPreviousPagefor navigation state - Update reactive variables to trigger query re-execution
