In this section, we’ll discuss another key step in the Gatsby build lifecycle and the enablement of GraphQL queries: the creation of schema root fields. In Gatsby, schema root fields are considered the “entry point” of any GraphQL query, also sometimes known as a top-level field. For each Node
type created during the process of schema generation, Gatsby generates two schema root fields. However, third-party schemas and implementations of the createResolvers
API are free to create additional fields.
The root fields generated by Gatsby are leveraged to retrieve either a single item of a certain Node
type or a collection of items of that type. For example, for a given type BlogArticle
, Gatsby will create on your behalf a blogArticle
(singular) and an allBlogArticle
(plural) root field. While these root fields are perfectly usable without arguments, both accept parameters that allow you to manipulate the returned data through filters, sorts, and pagination. Because these parameters depend on the given Node
type, Gatsby generates utility types to support them, which are types that enable pagination, sort, and filter operations and are used in the root fields accordingly.
Leave a Reply