Skip to content

fix(validation): unnecessary constraint forcing root query type #2422

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
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
18 changes: 0 additions & 18 deletions src/__tests__/graphql-test.js

This file was deleted.

31 changes: 0 additions & 31 deletions src/type/__tests__/validation-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -189,35 +189,6 @@ describe('Type System: A Schema must have Object root types', () => {
expect(validateSchema(schemaWithDef)).to.deep.equal([]);
});

it('rejects a Schema without a query type', () => {
const schema = buildSchema(`
type Mutation {
test: String
}
`);
expect(validateSchema(schema)).to.deep.equal([
{
message: 'Query root type must be provided.',
},
]);

const schemaWithDef = buildSchema(`
schema {
mutation: MutationRoot
}

type MutationRoot {
test: String
}
`);
expect(validateSchema(schemaWithDef)).to.deep.equal([
{
message: 'Query root type must be provided.',
locations: [{ line: 2, column: 7 }],
},
]);
});

it('rejects a Schema whose query root type is not an Object type', () => {
const schema = buildSchema(`
input Query {
Expand Down Expand Up @@ -2582,8 +2553,6 @@ describe('assertValidSchema', () => {
it('include multiple errors into a description', () => {
const schema = buildSchema('type SomeType');
expect(() => assertValidSchema(schema)).to.throw(dedent`
Query root type must be provided.

Type SomeType must define one or more fields.`);
});
});
4 changes: 1 addition & 3 deletions src/type/validate.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,7 @@ class SchemaValidationContext {
function validateRootTypes(context) {
const schema = context.schema;
const queryType = schema.getQueryType();
if (!queryType) {
context.reportError('Query root type must be provided.', schema.astNode);
} else if (!isObjectType(queryType)) {
if (queryType && !isObjectType(queryType)) {
context.reportError(
`Query root type must be Object type, it cannot be ${inspect(
queryType,
Expand Down