subsquid
Search…
Pagination
Paginate query results

The limit & offset arguments

The operators limit and offset are used for pagination.
limit specifies the number of entities to retain from the result set and offset determines which slice to retain from the results.
Default value for limit is 50 and offset is 0.
Limit results
Example: Fetch the first 5 channels:
1
query {
2
channels(limit: 5) {
3
id
4
handle
5
}
6
}
Copied!
Limit results from an offset
Example: Fetch 5 channels from the list of all channels, starting with the 6th one:
1
query {
2
channels(limit: 5, offset: 5) {
3
id
4
handle
5
}
6
}
Copied!

Cursor based pagination

Cursors are used to traverse across entities of an entity set. They work by returning a pointer to a specific entity which can then be used to fetch the next batch of entities.
For cursor based pagination for every entity in the input schema a query is generated with the <entityName>Connection pattern.
Example: Fetch a list of videos where isExplicit is true and get their count. Then limit the number of videos to return.
1
query {
2
videosConnection(where: { isExplicit_eq: true }) {
3
totalCount
4
edges {
5
node {
6
id
7
title
8
}
9
}
10
}
11
}
Copied!
first last operators
The first operator is used to fetch specified number of entities from the beginning and last is vice versa.
Example: Fetch first 5 videos and last 5 videos:
1
query Query1 {
2
videosConnection(first: 5) {
3
edges {
4
node {
5
id
6
title
7
}
8
}
9
}
10
}
11
12
query Query1 {
13
videosConnection(last: 5) {
14
edges {
15
node {
16
id
17
title
18
}
19
}
20
}
21
}
Copied!
PageInfo object
PageInfo returns the cursor, page information and object has following fields:
1
```json
2
pageInfo {
3
startCursor
4
endCursor
5
hasNextPage
6
hasPreviousPage
7
}
Copied!
before and after operators
Example: Fetch a first 10 channels order by createdAt and then fetch the next 10 channels:
1
query FirstBatchQ {
2
channelsConnection(first: 10, orderBy: createdAt_ASC) {
3
pageInfo {
4
endCursor
5
hasNextPage
6
}
7
edges {
8
node {
9
id
10
handle
11
createdAt
12
}
13
}
14
}
15
}
16
17
query SecondBatchQ {
18
channelsConnection(after: <endCursor>, orderBy: createdAt_ASC) {
19
pageInfo {
20
endCursor
21
hasNextPage
22
}
23
edges {
24
node {
25
id
26
handle
27
createdAt
28
}
29
}
30
}
31
}
Copied!
Example: Fetch a last 10 channels order by createdAt and then fetch the previous 10 channels:
1
query FirstBatchQ {
2
channelsConnection(last: 10, orderBy: createdAt_ASC) {
3
pageInfo {
4
endCursor
5
hasNextPage
6
}
7
edges {
8
node {
9
id
10
handle
11
createdAt
12
}
13
}
14
}
15
}
16
17
query SecondBatchQ {
18
channelsConnection(before: <endCursor>, orderBy: createdAt_ASC) {
19
pageInfo {
20
endCursor
21
hasNextPage
22
}
23
edges {
24
node {
25
id
26
handle
27
createdAt
28
}
29
}
30
}
31
}
Copied!
Important Note on orderBy
The field entities are ordered by should be fetch node { <fieldNameThatOrderedBy> } otherwise the returned result wouldn't be ordered correctly.
Last modified 7d ago