‎04-06-2020 04:18 PM - edited ‎26-10-2020 09:23 AM
When querying elements through the REST API a lot of items can be returned. To limit the size of items returned it can be relevant to paginate the data.
Pagination allows you to request a certain chunk of objects. You can seek forwards or backwards through the objects and supply an optional starting object:
To described the pagination we will take an example of a list 30 objects.
This sample query is on the Application object. With no pagination :
query application {
application {
id
name
}
}
As soon as a pagination is applied an implicit sort by "ID" is executed, therefore a query withtout pagination and order will not be sorted as a query with pagination.
You can get the first element and skip an arbitrary amount of objects in forward direction you are seeking by supplying the first, skip and after.
Five possibility of queries :
query application {
application(first:3) {
id
name
}
}​
query application {
application(first:3 skip:5) {
id
name
}
}​
query application {
application(first:3 after:"exeiHMRhHjHI" ) {
id
name
}
}​
query application {
application(first:3 skip:5 after:"exeiHMRhHjHI" ) {
id
name
}
}​
query application {
application( after:"exeiHMRhHjHI" ) {
id
name
}
}​
You can get the last element and skip an arbitrary amount of objects in backward direction you are seeking by supplying the first, skip and before.
Five possibility of queries :
query application {
application(last:3 ) {
id
name
}
}​
query application {
application(last:3 skip:5 ) {
id
name
}
}​
query application {
application(last:3 before:"ZEQyZ7FqOnxL") {
id
name
}
}​
query application {
application(last:3 skip:5 before:"ZEQyZ7FqOnxL") {
id
name
}
}​
query application {
application(before:"ZEQyZ7FqOnxL") {
id
name
}
}​
You cannot combine first with before or last with after. If you do so in a query, before or after will simply be ignored and only first or last is applied (at the very beginning or end of the list, depending on which you're using).
Note that you can query for more nodes than exist without an error message.
If you combined pagination option and order capabilities the pagination will be done after the sort is executed.
Example of query :
query application {
application(orderBy:[cloudComputing_ASC] first:3) {
id
name
cloudComputing
}
}