Skip to content

Commit 99377a2

Browse files
committed
document offset pagination
1 parent eb40d35 commit 99377a2

File tree

1 file changed

+63
-0
lines changed

1 file changed

+63
-0
lines changed

docs/api.md

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,11 @@ create table "Blog"(
133133
"""Query values in the collection after the provided cursor"""
134134
after: Cursor
135135

136+
"""
137+
Skip n values from the after cursor. Alternative to cursor pagination. Backward pagination not supported.
138+
"""
139+
offset: Int
140+
136141
"""Filters to apply to the results set when querying from the collection"""
137142
filter: BlogFilter
138143

@@ -264,6 +269,8 @@ Connections wrap a result set with some additional metadata.
264269

265270
#### Pagination
266271

272+
##### Keyset Pagination
273+
267274
Paginating forwards and backwards through collections is handled using the `first`, `last`, `before`, and `after` parameters, following the [relay spec](https://relay.dev/graphql/connections.htm#).
268275

269276
=== "QueryType"
@@ -436,6 +443,57 @@ once the collection has been fully enumerated, `data.blogConnection.pageInfo.has
436443

437444
To paginate backwards through a collection, repeat the process substituting `first` -> `last`, `after` -> `before`, `hasNextPage` -> `hasPreviousPage`
438445

446+
##### Offset Pagination
447+
448+
In addition to keyset pagination, collections may also be paged using `first` and `offset`, which operates like SQL's `limit` and `offset` to skip `offset` number of records in the results.
449+
450+
!!! note
451+
452+
`offset` based pagination becomes inefficient the `offset` value increases. For this reason, prefer cursor based pagination where possible.
453+
454+
455+
=== "Query"
456+
457+
```graphql
458+
{
459+
blogCollection(
460+
first: 2,
461+
offset: 2
462+
) {
463+
...truncated...
464+
}
465+
```
466+
467+
=== "Page 2"
468+
469+
```json
470+
{
471+
"data": {
472+
"blogCollection": {
473+
"edges": [
474+
{
475+
"node": {
476+
"id": 3
477+
},
478+
"cursor": "WzNd"
479+
},
480+
{
481+
"node": {
482+
"id": 4
483+
},
484+
"cursor": "WzRd"
485+
}
486+
],
487+
"pageInfo": {
488+
"startCursor": "WzNd",
489+
"endCursor": "WzRd",
490+
"hasNextPage": false,
491+
"hasPreviousPage": true
492+
}
493+
}
494+
}
495+
}
496+
```
439497

440498
#### Filtering
441499

@@ -1693,6 +1751,11 @@ create table "BlogPost"(
16931751
"""Query values in the collection after the provided cursor"""
16941752
after: Cursor
16951753

1754+
"""
1755+
Skip n values from the after cursor. Alternative to cursor pagination. Backward pagination not supported.
1756+
"""
1757+
offset: Int
1758+
16961759
"""Filters to apply to the results set when querying from the collection"""
16971760
filter: BlogPostFilter
16981761

0 commit comments

Comments
 (0)