Skip to content

Commit 63c2009

Browse files
authored
schema: fix error message when provided type has no name (#2475)
Avoid confusing error messages about "multiple types named undefined".
1 parent 905b7f3 commit 63c2009

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

src/type/__tests__/schema-test.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,19 @@ describe('Type System: Schema', () => {
357357
);
358358
});
359359

360+
it('rejects a Schema when a provided type has no name', () => {
361+
const query = new GraphQLObjectType({
362+
name: 'Query',
363+
fields: { foo: { type: GraphQLString } },
364+
});
365+
const types = [{}, query, {}];
366+
367+
// $DisableFlowOnNegativeTest
368+
expect(() => new GraphQLSchema({ query, types })).to.throw(
369+
'One of the provided types for building the Schema is missing a name.',
370+
);
371+
});
372+
360373
it('rejects a Schema which defines an object type twice', () => {
361374
const types = [
362375
new GraphQLObjectType({ name: 'SameName', fields: {} }),

src/type/schema.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,10 @@ export class GraphQLSchema {
213213
}
214214

215215
const typeName = namedType.name;
216+
devAssert(
217+
typeName,
218+
'One of the provided types for building the Schema is missing a name.',
219+
);
216220
if (this._typeMap[typeName] !== undefined) {
217221
throw new Error(
218222
`Schema must contain uniquely named types but contains multiple types named "${typeName}".`,

0 commit comments

Comments
 (0)