gatsbyjs/gatsby · critical

Encountered an error parsing the provided GraphQL type defin

Error message

Encountered an error parsing the provided GraphQL type definitions:\n${message}\n\n${frame}\n

What it means

This error fires when Gatsby's GraphQL type-definition parser (backed by @babel/code-frame for context) encounters a syntax error in SDL passed to createTypes. The message includes the parser's error message and a code frame showing the offending location. If no source/locations are available, the raw error is re-thrown instead.

Source

Thrown at packages/gatsby/src/schema/types/type-defs.js:37

    } catch (error) {
      reportParsingError(error)
    }
  }
  return typeOrTypeDef
}

const reportParsingError = error => {
  const { message, source, locations } = error

  if (source && locations && locations.length) {
    const { codeFrameColumns } = require(`@babel/code-frame`)

    const frame = codeFrameColumns(
      source.body,
      { start: locations[0] },
      { linesAbove: 5, linesBelow: 5 }
    )
    report.panic(
      `Encountered an error parsing the provided GraphQL type definitions:\n` +
        message +
        `\n\n` +
        frame +
        `\n`
    )
  } else {
    throw error
  }
}

/**
 * Given a type definition, collects type names that should skip the inference process
 */
const typesWithoutInference = (typeNames = [], typeOrTypeDef) => {
  if (typeof typeOrTypeDef === `string`) {
    typeOrTypeDef = parseTypeDef(typeOrTypeDef)
  }

View on GitHub (pinned to 8b06340921)

Solutions

  1. Read the code frame in the error output -- it pinpoints the exact line and column of the syntax error.
  2. Validate your SDL string with a GraphQL playground or the graphql package's parse() before passing to createTypes.
  3. Check for unbalanced braces, missing colons, invalid field types, and stray characters in the SDL template literal.
  4. If building SDL dynamically, log the generated string and inspect it for correctness.

Example fix

// before -- missing closing brace
actions.createTypes(`
  type Post {
    title: String
`)

// after
actions.createTypes(`
  type Post {
    title: String
  }
`)
Defensive patterns

Strategy: validation

Validate before calling

// Validate SDL syntax before passing to createTypes
const { parse } = require('graphql')

function validateSDL(sdlString) {
  try {
    parse(sdlString)
    return { valid: true }
  } catch (err) {
    return { valid: false, error: err.message, locations: err.locations }
  }
}

const result = validateSDL(myTypeDefs)
if (!result.valid) {
  console.error('Invalid SDL:', result.error, result.locations)
}

Prevention

When it happens

Trigger: Passing malformed GraphQL SDL string(s) to actions.createTypes() -- missing braces, invalid directive syntax, unbalanced parentheses, reserved keyword misuse, or concatenating multiple type strings incorrectly.

Common situations: A template literal in createTypes has a typo or unclosed brace. Dynamically generating SDL with a bug in the string builder. Copying SDL from a doc that got mangled. Plugin schema extension with invalid syntax.

Related errors


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