gatsbyjs/gatsby · error

Expected array field value.

Error message

Expected array field value.

What it means

validate() expects an Array when the type is GraphQLList. It throws when a list-typed field/argument is given a non-array value during default-value or literal validation.

Source

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

// 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 => {
    if (type instanceof InterfaceTypeComposer && isNodeInterface(type)) {
      queryableInterfaces.add(type.getTypeName())
    }
  })
  const incorrectTypes = new Set()

View on GitHub (pinned to 8b06340921)

Solutions

  1. Wrap the value in an array at the source/resolver level.
  2. Correct the declared type (use scalar instead of [scalar]) if a single value is intended.
  3. Transform data in sourceNodes so list fields always yield arrays.

Example fix

// before: tags declared [String!] but node has tags: "a,b"
type Post implements Node { tags: [String!]! }
// after: normalize to an array in sourceNodes
actions.createNode({ ...node, tags: typeof node.tags === 'string' ? node.tags.split(',') : node.tags ?? [] })
Defensive patterns

Strategy: validation

Validate before calling

const { GraphQLList } = require('graphql')
function ensureArrayForListType(type, value) {
  if (type instanceof GraphQLList && !Array.isArray(value)) {
    return Array.isArray(value) ? value : (value == null ? [] : [value])
  }
  return value
}

Type guard

function isListType(type) { return type instanceof GraphQLList }

Prevention

When it happens

Trigger: A field/argument declared [Type!] receiving a single scalar/object instead of an array during validate (default values, input coercion, directive args).

Common situations: Source data providing one value where the schema expects a list; schema customization type mismatch (declared list, returned scalar); incorrect default values in directives.

Related errors


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