gatsbyjs/gatsby · error

Expected non-null field value.

Error message

Expected non-null field value.

What it means

validate() recurses a GraphQL type to parse/coerce a runtime value (used for default values and argument literals). When the type is GraphQLNonNull and the value is null/undefined, it throws. It indicates a null reached a field/argument the schema declared as non-null.

Source

Thrown at packages/gatsby/src/schema/schema.js:1367

const stringifyArray = arr =>
  `[${arr.map(item =>
    Array.isArray(item) ? stringifyArray(item) : item.toString()
  )}]`

// TODO: Import this directly from graphql-compose once we update to v7
const isNamedTypeComposer = type =>
  type instanceof ObjectTypeComposer ||
  type instanceof InputTypeComposer ||
  type instanceof ScalarTypeComposer ||
  type instanceof EnumTypeComposer ||
  type instanceof InterfaceTypeComposer ||
  type instanceof UnionTypeComposer

const validate = (type, value) => {
  if (type instanceof GraphQLNonNull) {
    if (value == null) {
      throw new Error(`Expected non-null field value.`)
    }
    return validate(type.ofType, value)
  } else if (type instanceof GraphQLList) {
    if (!Array.isArray(value)) {
      throw new Error(`Expected array field value.`)
    }
    return value.map(v => validate(type.ofType, v))
  } else {
    return type.parseValue(value)
  }
}

const isNodeInterface = interfaceTypeComposer =>
  interfaceTypeComposer.hasInterface(`Node`)

const checkQueryableInterfaces = ({ schemaComposer }) => {
  const queryableInterfaces = new Set()
  schemaComposer.forEach(type => {

View on GitHub (pinned to 8b06340921)

Solutions

  1. Ensure the non-null field always receives a concrete value (fix resolver/source data).
  2. Make the declared type nullable (remove the !) if null is legitimately possible.
  3. Provide an explicit non-null defaultValue in the schema customization.

Example fix

// before: field declared non-null but value resolves to null -> [162]
type Product implements Node { price: Float! }
// after: allow null, or supply a default
type Product implements Node { price: Float }
// or in createResolvers:
Product: { price: { resolve: (s) => s.price ?? 0 } }
Defensive patterns

Strategy: validation

Validate before calling

const { GraphQLNonNull, GraphQLList } = require('graphql')
function assertValidForType(type, value) {
  if (type instanceof GraphQLNonNull && value == null) {
    throw new Error(`Refusing to validate null against non-null ${type}`)
  }
}

Type guard

function isNonNullType(type) { return type instanceof GraphQLNonNull }

Prevention

When it happens

Trigger: Validating a default value or input literal against a non-null type where the supplied value resolves to null; a resolver returning null for a non-null field during default-value materialization.

Common situations: Schema customization with non-null fields whose default/resolved value is null; a plugin returning null where the declared type is Type!; fixture/test data missing a required field.

Related errors


AI-assisted analysis of gatsbyjs/gatsby@8b06340921 (2026-08-13). Data as JSON: /api/errors/72b91e6115fdba93. Report an issue: GitHub.