Skip to content
Latchkey

GraphQL "There can be only one type named X" in CI

graphql-js validates the SDL document itself and rejects two definitions of the same type name with "There can be only one type named X". This is the SDL-level sibling of the uniquely-named-types build error.

What this error means

A schema validation or codegen-free build step reports "There can be only one type named \"Query\"." (or any type), pointing at two locations in the SDL.

graphql-js
GraphQLError: There can be only one type named "Query".
  locations: [ { line: 1, column: 6 }, { line: 40, column: 6 } ]

Common causes

Query or Mutation declared twice

Two files each open type Query { ... }; only one base definition is allowed, with additions via extend type Query.

A copy-pasted type left in the SDL

A duplicated block (often from a merge conflict resolution) leaves two definitions of the same object or input type.

How to fix it

Convert duplicates to extensions

  1. Open both locations the error reports.
  2. Keep one type X and rewrite the other as extend type X.
  3. Re-validate the SDL.
GraphQL
# base file
type Query { user(id: ID!): User }

# other file: extend, do not redeclare
extend type Query { posts: [Post!]! }

Lint the SDL in CI

Run a schema validation step so a duplicate root type fails the pipeline immediately.

Terminal
npx graphql-schema-linter schema.graphql

How to prevent it

  • Use exactly one base definition per type and extend type elsewhere.
  • Resolve merge conflicts carefully so no type block is duplicated.
  • Validate the assembled SDL as a CI gate.

Frequently asked questions

What causes ""There can be only one type named X""?
Two files each open type Query { ... }; only one base definition is allowed, with additions via extend type Query.
How do I fix "There can be only one type named X"?
Convert duplicates to extensions

Related guides

References

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