Category: Uncategorized

  • Inferring child and parent fields

    In this section, we’ll examine the schema inference Gatsby undertakes to define child fields that have a relationship to their parent field. Consider the example of the File type, for which many transformer plugins exist that convert a file’s contents into a format legible to Gatsby’s data layer. When transformer plugins implement onCreateNode for each File node, this implementation produces File child nodes that carry their…

  • Inferring fields on the created Node object

    Fields that are directly created on the node, meaning fields that are provided through source and transformer plugins (e.g., relativePath, size, and accessTime in nodes of type File), are typically queried through the GraphQL API in a query similar to the following: These fields are created using the inferObjectStructureFromNodes function in src/schema/infer-graphql-type.js. Based on what kind of object the function is dealing with as it…

  • Schema Inference

    Each time a node is created, yielding a newly sourced or transformed node, Gatsby generates inference metadata that can be merged with other metadata such that it’s possible to define a schema for the new node that is as specific as possible to its structure. Thanks to inference metadata, Gatsby can also understand if there are any conflicts in…

  • 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…

  • Handling stale nodes

    Each time you run the gatsby build command, because Gatsby is fundamentally an SSG, there is always a nonzero chance that some node in the Redux nodes namespace will no longer be available because it’s been removed from the upstream data source. The Gatsby build lifecycle needs to be aware of this event in order to handle all nodes appropriately.…

  • Establishing parent and child relationships

    Many nodes have a relationship to a parent node or child node that establishes a dependency between the two. Gatsby’s build process provides several approaches to create these relationships, which isn’t straightforward due to the fact that all nodes are considered top-level objects in the Redux nodes namespace. For this reason, each node’s children field consists of an array of…

  • Node Creation

    The createNode API, one of the Gatsby Node APIs, is responsible for creating nodes, which can take the form of any object. Within Redux, which Gatsby leverages to manage state, nodes are stored under the nodes namespace. The nodes namespace carries state in the form of a map of Node identifiers to Node objects. Node creation happens first and foremost in the sourceNodes bootstrap stage, and all nodes…

  • The Gatsby Build Lifecycle

    The Gatsby build lifecycle consists of a series of steps, many of which will be recognizable from the overviews of some of these APIs in previous sections. After nodes are sourced and created, a schema is generated to facilitate GraphQL queries in Gatsby pages and components. Thereafter, the queries are executed to create the pages that…

  • Executing Plugins and Injecting Arguments

    Once the previous step is complete, the Gatsby bootstrap filters the flattenedPlugins namespace in Redux to yield only the plugins that implement the Gatsby API that needs to be executed. For each successive plugin it encounters, Gatsby will require its gatsby-node.js file and invoke its exported function that implements one of the Gatsby Node APIs. For instance, if the API…

  • The apiRunInstance Object

    Because some API calls in Gatsby can take longer to finish than others, every time an API is invoked, the Gatsby bootstrap creates an object called apiRunInstance to track the call. This object contains the fields listed in Table 14-2. Field Description id A unique identifier generated based on the type of API invoked api The API being invoked; e.g., onCreateNode args…