Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion src/utilities/__tests__/buildASTSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,6 @@ type Hello { testUnion: TestUnion }
.to.throw('Type Bar not found in document');
});


it('Unknown query type', () => {
var body = `
type Hello {
Expand All @@ -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');
});
});
9 changes: 5 additions & 4 deletions src/utilities/buildASTSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]);
Expand Down