Pagination
Make sure to include pagination parameters in queries to avoid network time out errors
For any query that returns a list of results, we highly recommend using pagination. If pagination is not applied, it is much more likely that a network timeout error (in the form of a 502 error) will be returned. This occurs when an API call doesn't receive a response for 30 seconds. Pagination allows you to return a smaller data payload by returning a subset of the results to avoid the timeout error. It subsequently gives you a way to query further results as needed.
In this example, the parts query grabs the first five parts by utilizing the
first
parameter and fetch the endCursor
in the pageInfo
object as shown in the request as shown below.{
parts(first: 5) {
edges {
node {
id
}
}
pageInfo {
endCursor #use this to grab the next set of parts
hasNextPage #are their more parts after the ones returned in this query?
totalCount #total number of parts
count #number of parts returned by this query
}
}
}
Example Response
"data": {
"procedures": {
"edges": [
{
"node": {
"id": 20
}
},
{
"node": {
"id": 22
}
},
{
"node": {
"id": 24
}
},
{
"node": {
"id": 26
}
},
{
"node": {
"id": 28
}
}
],
"pageInfo": {
"endCursor": "YXJyYXljb25uZWN0aW9uOjE5",
"hasNextPage": true,
"totalCount": 1259,
"count": 5
}
}
}
}
In addition to
first
, ION queries have pagination parameters of last
, before
, and after
.In this next example, this parts query returns the next five 5 parts after the part identified by the
endCursor
from the previous query. If all parts in ION were to be queried, this pattern can be used to fetch all parts in batches of 5. In addition, use the hasNextPage
to determine if there are more results remaining after this query.{
parts(first: 5, after: "YXJyYXljb25uZWN0aW9uOjE5") {
edges {
node {
id
}
}
pageInfo {
endCursor #use this to grab the next set of parts
hasNextPage #are their more parts after the ones returned in this query?
totalCount #total number of parts
count #number of parts returned by this query
}
}
}
Last modified 1mo ago