GraphQL Pagination
In this lesson, we will be introducing the GraphQL feature: pagination.
We'll cover the following...
Why Do we Need Pagination?
This is where we return to the concept of pagination mentioned in the previous chapter. Imagine we have a list of repositories in our GitHub organization, but we only want to retrieve a few of them to display on our UI. It could take ages to fetch a list of repositories from a large organization. In GraphQL, you can request paginated data by providing arguments to a list field, such as an argument that specifies how many items you are expecting from the list.
query OrganizationForLearningReact {organization(login: "the-road-to-learn-react") {nameurlrepositories(first: 2) {edges {node {name}}}}}
An argument, namely first
, is passed to the repositories
list field that specifies how many items from the list are expected in the result. The query shape doesn’t need to follow the edges
and node
structure, but it’s one from a few solutions to define paginated data structures and lists with GraphQL. Actually, it follows the ...