Pagination using limit & offset

Using offset and limit parameters to paginate data is one of the most widely used techniques for pagination.

Clients provide the limit parameter indicating the number of results they want per page, and the offset parameter to specify the results to skip.

GraphQLize supports these parameters to paginate via table or view queries. It also supports pagination of nested objects.

Using Limit alone

By using the limit alone, we can restrict the number of results that we want.

query {
actors(limit: 2) {
actorId
firstName
lastName
}
}

The above query returns two actor's details as output.

{
"data": {
"actors": [
{
"actorId": 1,
"firstName": "PENELOPE",
"lastName": "GUINESS"
},
{
"actorId": 2,
"firstName": "NICK",
"lastName": "WAHLBERG"
}
]
}
}

Using Offset with Limit

Let's assume in the above example we want to view the next two actors. We can achieve it by using offset along with the limit.

query {
actors(limit: 2, offset: 2) {
actorId
firstName
lastName
}
}

It returns

{
"data": {
"actors": [
{
"actorId": 3,
"firstName": "ED",
"lastName": "CHASE"
},
{
"actorId": 4,
"firstName": "JENNIFER",
"lastName": "DAVIS"
}
]
}
}
note

MySQL doesn't support using the offset paramater alone.

Paginate Nested Objects

GraphQLize supports using limit & offset in the nested objects as well.

One to Many Relationships

query {
countryByCountryId(countryId: 6) {
country
cities(limit: 2, offset : 4) {
city
}
}
}

Many to Many Relationships

query {
actorByActorId(actorId: 1) {
firstName
films(limit: 5, offset: 5) {
title
}
}
}