Imagine that your Hackernews has thousands of created links – that would be awesome for you – but the clients making the request wouldn’t be happy. Retrieving too much data on a single request is unpractical and may even break your app. Pagination exists to solve this problem, allowing the client to specify how many items it wants.

The simple way defined in the GraphQL pagination documentation is to slice the results using two parameters: first, which returns the first n items and skip, which skips the first n items.

Let’s implement it on the links query.

Paginating Links

The skip and first uses Python Slicing.

Testing it on the GraphiQL interface:

Unlock the next chapter
Why pagination in queries are important?
To show all the information at once
Allows the client to say how much data it wants
To filter results by specific fields
GraphQL can't runt without pagination