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.
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
- Search the SDL set for every definition of the named type.
- Keep a single
type X { ... }and convert the others toextend type X { ... }. - Rebuild the schema to confirm the duplicate is gone.
# find every definition of the duplicated type
grep -rn "type User" src/**/*.graphqlMerge typedefs with a tool that dedupes
Use a schema-merging utility so repeated definitions collapse instead of producing duplicates.
import { mergeTypeDefs } from '@graphql-tools/merge';
const typeDefs = mergeTypeDefs(loadedSdlArray);How to prevent it
- Define each type once and use
extend typeeverywhere else. - Merge SDL with @graphql-tools/merge rather than naive concatenation.
- Add a schema-build step to CI so duplicates fail before deploy.