Gatsby createSchemaCustomization and MarkdownRemark: can't force html to be non-nullable

I have a static blog that I generate with Gatsby from markdown files using gatsby-transformer-remark plugin. I use typescript and generate the types for graphql queries as discussed here.

To simplify working in typescript, I’d like to change the GraphQL schema so that html field (i.e. the one mentioned here) is non-nullable. To do so, I follow the documentation and define the following in my gatsby-node.ts, in createSchemaCustomization:

exports.createSchemaCustomization = ({ actions }: CreateSchemaCustomizationArgs) => {
  const { createTypes } = actions;
  const typeDefs = `
    type MarkdownRemark {
      fields: MarkdownRemarkFields!
      frontmatter: Frontmatter!
      html: String!

This works to make fields and frontmatter non-nullable everywhere: i.e. I can do node.fields.slug now, instead of node.fields!.slug. But, for some reason, this never works for html. html is still string | null everywhere.

Why is it so? Is that a bug or am I doing something wrong?


  • Gatsby 5.13.1
  • npm 10.2.3
  • node v20.10.0
  • I am running everything in a VS Code dev container:

It should work. Mind providing a reproduction repo?