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).
Field | Description |
---|---|
edges | An 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. |
nodes | A flat list of Node objects. |
pageInfo | Contains additional pagination metadata. |
pageInfo.totalCount | The number of all nodes that match the filter prior to pagination (also available as totalCount ). |
pageInfo.currentPage | The index of the current page (starting with 1). |
pageInfo.hasNextPage , pageInfo.hasPreviousPage | Whether a previous or next page is available based on the current paginated page. |
pageInfo.itemCount | The number of items on the current page. |
perPage | The requested number of items on each page. |
pageCount | The 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.
Leave a Reply