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.
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
- Open both locations the error reports.
- Keep one
type Xand rewrite the other asextend type X. - Re-validate the SDL.
# 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.
npx graphql-schema-linter schema.graphqlHow to prevent it
- Use exactly one base definition per type and
extend typeelsewhere. - Resolve merge conflicts carefully so no type block is duplicated.
- Validate the assembled SDL as a CI gate.