diff --git a/src/utilities/__tests__/buildASTSchema.js b/src/utilities/__tests__/buildASTSchema.js index 79c35cbcb1..a6fe4cbb50 100644 --- a/src/utilities/__tests__/buildASTSchema.js +++ b/src/utilities/__tests__/buildASTSchema.js @@ -320,7 +320,6 @@ type Hello { testUnion: TestUnion } .to.throw('Type Bar not found in document'); }); - it('Unknown query type', () => { var body = ` type Hello { @@ -331,4 +330,15 @@ type Hello { expect(() => buildASTSchema(doc, 'Wat')) .to.throw('Specified query type Wat not found in document'); }); + + it('Unknown mutation type', () => { + var body = ` +type Hello { + str: String +} +`; + var doc = parseSchemaIntoAST(body); + expect(() => buildASTSchema(doc, 'Hello', 'Wat')) + .to.throw('Specified mutation type Wat not found in document'); + }); }); diff --git a/src/utilities/buildASTSchema.js b/src/utilities/buildASTSchema.js index dfe64e713d..04f6fb16c8 100644 --- a/src/utilities/buildASTSchema.js +++ b/src/utilities/buildASTSchema.js @@ -105,6 +105,11 @@ export function buildASTSchema( ' not found in document.'); } + if (!isNullish(mutationTypeName) && isNullish(astMap[mutationTypeName])) { + throw new Error('Specified mutation type ' + mutationTypeName + + ' not found in document.'); + } + /** * This generates a function that allows you to produce * type definitions on demand. We produce the function @@ -142,10 +147,6 @@ export function buildASTSchema( var produceTypeDef = getTypeDefProducer(ast); - if (isNullish(astMap[queryTypeName])) { - throw new Error(`Type ${queryTypeName} not found in document`); - } - ast.definitions.forEach(produceTypeDef); var queryType = produceTypeDef(astMap[queryTypeName]);