Skip to content
Latchkey

GraphQL Code Generator "Syntax Error: Unexpected Name" in CI

GraphQL Code Generator parses your SDL and operation documents with the graphql-js parser. A malformed type or operation raises "Syntax Error: Unexpected Name ..." with the file and position of the token the parser did not expect.

What this error means

graphql-codegen fails with "Syntax Error: Unexpected Name \"<token>\"." and a source location, usually pointing at a typo in a schema or query file.

graphql-codegen
Syntax Error: Unexpected Name "tpye".

GraphQL request:3:3
2 | type User {
3 |   tpye String
  |   ^

Common causes

A typo or missing punctuation in SDL

A misspelled keyword, a missing colon between a field and its type, or a stray token makes the parser report an unexpected name.

A non-GraphQL file matched the documents glob

The documents glob picked up a file that is not valid GraphQL, so the parser chokes on its contents.

How to fix it

Fix the SDL at the reported position

  1. Open the file and line from the error.
  2. Correct the typo or add the missing :/punctuation.
  3. Re-run codegen to confirm the document parses.
schema.graphql
type User {
  type: String
}

Narrow the documents glob

Restrict the glob so it only matches real .graphql/.gql files and excludes anything that is not GraphQL.

codegen.yml
# codegen.yml
documents:
  - 'src/**/*.graphql'
  - '!src/**/__generated__/**'

How to prevent it

  • Validate SDL and operations with a linter before codegen.
  • Keep the documents glob tight so it only matches GraphQL files.
  • Run codegen locally so syntax errors surface before CI.

Frequently asked questions

What causes ""Syntax Error: Unexpected Name""?
A misspelled keyword, a missing colon between a field and its type, or a stray token makes the parser report an unexpected name.
How do I fix "Syntax Error: Unexpected Name"?
Fix the SDL at the reported position

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card