Why Use This Approach?
Using cursor-based pagination offers several advantages:- Efficient Data Handling: Cursors are more efficient than offset-based pagination, especially with large or frequently updated datasets.
- Consistency: It avoids issues with data shifting between requests (e.g., when new trainings are added or removed), ensuring stable navigation through paginated results.
- Scalability: Better performance on large datasets, as it avoids skipping records and leverages indexed fields.
- Built-in Navigation: The specification provides standard ways to handle forward and backward navigation (e.g.,
hasNextPage
,endCursor
), simplifying client-side implementation.
getCatalogData
query includes a pageInfo
field, which provides metadata about the current result set and allows clients to effectively implement pagination.
Fields:
hasNextPage
(Boolean
)
Indicates whether there are more results available after the current page.true
→ Additional pages exist.false
→ You’ve reached the end of the list.
startCursor
(String
)
A cursor string representing the first item in the current page. It can be used as thebefore
parameter to fetch the previous page, if needed.endCursor
(String
)
A cursor string representing the last item in the current page. This value should be used as theafter
parameter when querying the next page of results.
Note: The cursor values (such as the encoded strings shown above) are opaque and should not be parsed or modified by clients—they are meant to be passed back to the API exactly as received.
Utilizing pageInfo in the getCatalogData Query
Building on the explanation of thepageInfo
fields—hasNextPage
, startCursor
, and endCursor
—these values can now be applied in the getCatalogData
query to control pagination behavior.
By using the endCursor
as the after
argument, clients can request the next page of results. Similarly, the startCursor
can be passed as the before
argument to retrieve the previous page. This approach enables efficient, cursor-based pagination that ensures consistent data retrieval, even in dynamic datasets. Please see the full list of available pagination arguments for the getCatalogData
query:
Argument | Type | Description |
---|---|---|
after | Cursor | Returns the elements after the specified cursor. Use for forward pagination. |
before | Cursor | Returns the elements before the specified cursor. Use for backward pagination. |
first | Int | Limits the result to the first n elements after the after cursor. |
last | Int | Limits the result to the last n elements before the before cursor. |
⚖️ Pagination Input Validation
ThegetCatalogData
query supports two mutually exclusive pagination approaches. In both cases, the number of items returned must not exceed the limit of 100.
Pagination Type | Required Argument(s) | Optional Cursor | Constraints |
---|---|---|---|
Forward | first | after | first must be > 0 and ≤ 100 |
Backward | last | before | last must be > 0 and ≤ 100 |
- Providing both
first
andlast
- Using
first
withbefore
- Using
last
withafter
- Providing values ≤ 0 or > 100 for
first
orlast
🔁 Loading the Next Page
To load the next set of catalog items, pass theendCursor
value from the pageInfo
object of the previous result into the after
argument.
In case you reach the end of the catalog, the
pageInfo.hasNextPage
field will be set to false