Skip to content

Commit 8385b7b

Browse files
committed
Merge pull request #108 from graphql/mutationname
Add check for unknown mutation type
2 parents e99fc53 + 5262885 commit 8385b7b

File tree

2 files changed

+16
-5
lines changed

2 files changed

+16
-5
lines changed

src/utilities/__tests__/buildASTSchema.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,6 @@ type Hello { testUnion: TestUnion }
320320
.to.throw('Type Bar not found in document');
321321
});
322322

323-
324323
it('Unknown query type', () => {
325324
var body = `
326325
type Hello {
@@ -331,4 +330,15 @@ type Hello {
331330
expect(() => buildASTSchema(doc, 'Wat'))
332331
.to.throw('Specified query type Wat not found in document');
333332
});
333+
334+
it('Unknown mutation type', () => {
335+
var body = `
336+
type Hello {
337+
str: String
338+
}
339+
`;
340+
var doc = parseSchemaIntoAST(body);
341+
expect(() => buildASTSchema(doc, 'Hello', 'Wat'))
342+
.to.throw('Specified mutation type Wat not found in document');
343+
});
334344
});

src/utilities/buildASTSchema.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,11 @@ export function buildASTSchema(
105105
' not found in document.');
106106
}
107107

108+
if (!isNullish(mutationTypeName) && isNullish(astMap[mutationTypeName])) {
109+
throw new Error('Specified mutation type ' + mutationTypeName +
110+
' not found in document.');
111+
}
112+
108113
/**
109114
* This generates a function that allows you to produce
110115
* type definitions on demand. We produce the function
@@ -142,10 +147,6 @@ export function buildASTSchema(
142147

143148
var produceTypeDef = getTypeDefProducer(ast);
144149

145-
if (isNullish(astMap[queryTypeName])) {
146-
throw new Error(`Type ${queryTypeName} not found in document`);
147-
}
148-
149150
ast.definitions.forEach(produceTypeDef);
150151

151152
var queryType = produceTypeDef(astMap[queryTypeName]);

0 commit comments

Comments
 (0)