Schema Generation

After the nodes in your Gatsby site have been sourced from upstream data sources and transformed where necessary through plugins and their implementations of Gatsby APIs, it’s time for Gatsby to generate the schema underlying the GraphQL API driving data in your Gatsby implementation. Schema generation involves several steps.

Gatsby’s GraphQL schema differs considerably from many other GraphQL schemas in the wild because it synthesizes plugin- and user-defined schema information together with data inferred from the way the sourced and transformed nodes are themselves structured. The former process involves creating a schema based on data presented to Gatsby, whereas the latter process, schema inference, involves inferring a schema based on how nodes are shaped.

Both developers and plugin authors in Gatsby have the ability to define the schema themselves through a process known as schema customization, which we covered in the previous section. Typically, every node receives a certain type in GraphQL based on the way its node.internal.type field is defined. For example, when you leverage Gatsby’s schema customization API to explicitly define the GraphQL type, all types that implement Gatsby’s Node interface will in turn become resources of type Node in GraphQL, in the process having their root-level fields defined in the GraphQL schema as well.

NOTE

In Gatsby, schema generation is a process that leverages the graphql-compose library, which is a toolkit used by many GraphQL API creators to generate schemas programmatically. For more information about this library, consult the graphql-compose documentation.


Posted

in

,

by

Tags:

Comments

Leave a Reply

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