2018-09-11 14:11:24 +03:00
|
|
|
Paginate query results
|
|
|
|
======================
|
2018-12-03 15:12:24 +03:00
|
|
|
|
|
|
|
.. contents:: Table of contents
|
|
|
|
:backlinks: none
|
|
|
|
:depth: 1
|
|
|
|
:local:
|
|
|
|
|
2018-10-31 16:49:29 +03:00
|
|
|
The operators :ref:`limit <PaginationExp>` and :ref:`offset <PaginationExp>` are used for pagination.
|
|
|
|
``limit`` specifies the number of rows to retain from the result set
|
|
|
|
and ``offset`` determines which slice to retain from the results.
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
The following are examples of pagination in different scenarios:
|
|
|
|
|
|
|
|
Limit results
|
|
|
|
-------------
|
|
|
|
Fetch the first 5 authors from the list of all authors:
|
|
|
|
|
|
|
|
.. graphiql::
|
|
|
|
:view_only:
|
|
|
|
:query:
|
|
|
|
query {
|
|
|
|
author(
|
|
|
|
limit: 5
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
:response:
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"author": [
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Justin"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"name": "Beltran"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"name": "Sidney"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 4,
|
|
|
|
"name": "Anjela"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 5,
|
|
|
|
"name": "Amii"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Limit results from an offset
|
|
|
|
----------------------------
|
|
|
|
Fetch 5 authors from the list of all authors, starting with the 6th one:
|
|
|
|
|
|
|
|
.. graphiql::
|
|
|
|
:view_only:
|
|
|
|
:query:
|
|
|
|
query {
|
|
|
|
author(
|
|
|
|
limit: 5,
|
|
|
|
offset:5
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
}
|
|
|
|
}
|
|
|
|
:response:
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"author": [
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"name": "Corny"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 7,
|
|
|
|
"name": "Berti"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 8,
|
|
|
|
"name": "April"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 9,
|
|
|
|
"name": "Ninnetta"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 10,
|
|
|
|
"name": "Lyndsay"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Limit results in a nested object
|
|
|
|
--------------------------------
|
2018-10-12 07:00:25 +03:00
|
|
|
Fetch a list of authors and a list of 2 of each of their articles:
|
2018-09-11 14:11:24 +03:00
|
|
|
|
|
|
|
.. graphiql::
|
|
|
|
:view_only:
|
|
|
|
:query:
|
|
|
|
query {
|
|
|
|
author {
|
|
|
|
id
|
|
|
|
name
|
|
|
|
articles (
|
|
|
|
limit:2
|
|
|
|
) {
|
|
|
|
id
|
|
|
|
title
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
:response:
|
|
|
|
{
|
|
|
|
"data": {
|
|
|
|
"author": [
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"name": "Justin",
|
|
|
|
"articles": [
|
|
|
|
{
|
|
|
|
"id": 15,
|
|
|
|
"title": "vel dapibus at"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 16,
|
|
|
|
"title": "sem duis aliquam"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"name": "Beltran",
|
|
|
|
"articles": [
|
|
|
|
{
|
|
|
|
"id": 2,
|
|
|
|
"title": "a nibh"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 9,
|
|
|
|
"title": "sit amet"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"name": "Sidney",
|
|
|
|
"articles": [
|
|
|
|
{
|
|
|
|
"id": 6,
|
|
|
|
"title": "sapien ut"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 11,
|
|
|
|
"title": "turpis eget"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 4,
|
|
|
|
"name": "Anjela",
|
|
|
|
"articles": [
|
|
|
|
{
|
|
|
|
"id": 1,
|
|
|
|
"title": "sit amet"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"id": 3,
|
|
|
|
"title": "amet justo morbi"
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2018-10-12 07:00:25 +03:00
|
|
|
}
|