Pagination types

As we saw earlier in this section, when a group of nodes is returned in response to a plural root field query, the type returned is Connection, which represents a common pattern in GraphQL. The term connection refers to an abstraction that operates over paginated resources. When you query a connection in GraphQL, Gatsby returns a subset of the resulting data based on defined skip and limit parameters, but you can also perform additional operations on the collection, such as grouping or distinction, as seen in the last two rows the following table (Table 14-3).

FieldDescription
edgesAn edge is the actual Node object combined with additional metadata indicating its location in the paginated page; edges is a list of these objects. The edge object contains node, the actual object, and next and prev objects to retrieve the objects representing adjacent pages.
nodesA flat list of Node objects.
pageInfoContains additional pagination metadata.
pageInfo.totalCountThe number of all nodes that match the filter prior to pagination (also available as totalCount).
pageInfo.currentPageThe index of the current page (starting with 1).
pageInfo.hasNextPagepageInfo.hasPreviousPageWhether a previous or next page is available based on the current paginated page.
pageInfo.itemCountThe number of items on the current page.
perPageThe requested number of items on each page.
pageCountThe total number of pages.
distinct(field)Prints distinct values for a given field.
group(field)Returns values grouped by a given field.
NOTE

For more information about the Connection convention in GraphQL, consult the Relay documentation’s page on the connection model.


Posted

in

,

by

Tags:

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *