Skip to content
Latchkey

GraphQL "Schema must contain uniquely named types" in CI

When buildSchema or makeExecutableSchema assembles your SDL, every type name must be unique. Two definitions sharing a name (often from merging multiple .graphql files) throw "Schema must contain uniquely named types".

What this error means

Server startup or a schema-build step throws "Error: Schema must contain uniquely named types but contains multiple types named \"X\".", failing the CI job before tests run.

graphql-js
Error: Schema must contain uniquely named types but contains multiple types named "User".
    at typeMapReducer (/app/node_modules/graphql/type/schema.js:...)

Common causes

The same type is defined in two files

Glob-merged SDL includes two files that each declare type User, so the merged document has a duplicate definition.

A scalar or type redefined alongside an extension

A base type is declared twice instead of one type plus extend type, producing two full definitions of the same name.

How to fix it

Keep one definition and extend the rest

  1. Search the SDL set for every definition of the named type.
  2. Keep a single type X { ... } and convert the others to extend type X { ... }.
  3. Rebuild the schema to confirm the duplicate is gone.
Terminal
# find every definition of the duplicated type
grep -rn "type User" src/**/*.graphql

Merge typedefs with a tool that dedupes

Use a schema-merging utility so repeated definitions collapse instead of producing duplicates.

JavaScript
import { mergeTypeDefs } from '@graphql-tools/merge';
const typeDefs = mergeTypeDefs(loadedSdlArray);

How to prevent it

  • Define each type once and use extend type everywhere else.
  • Merge SDL with @graphql-tools/merge rather than naive concatenation.
  • Add a schema-build step to CI so duplicates fail before deploy.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →