Skip to content

Commit 64533d4

Browse files
author
Victor Andrée
committed
Remove missing fields validation for composite types
See: graphql/graphql-spec#606
1 parent b113ef7 commit 64533d4

File tree

2 files changed

+6
-40
lines changed

2 files changed

+6
-40
lines changed

src/type/__tests__/validation-test.js

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -407,32 +407,23 @@ describe('Type System: Objects must have fields', () => {
407407
expect(validateSchema(schema)).to.deep.equal([]);
408408
});
409409

410-
it('rejects an Object type with missing fields', () => {
410+
it('accepts an Object type with missing fields', () => {
411411
const schema = buildSchema(`
412412
type Query {
413413
test: IncompleteObject
414414
}
415415
416416
type IncompleteObject
417417
`);
418-
expect(validateSchema(schema)).to.deep.equal([
419-
{
420-
message: 'Type IncompleteObject must define one or more fields.',
421-
locations: [{ line: 6, column: 7 }],
422-
},
423-
]);
418+
expect(validateSchema(schema)).to.deep.equal([]);
424419

425420
const manualSchema = schemaWithFieldType(
426421
new GraphQLObjectType({
427422
name: 'IncompleteObject',
428423
fields: {},
429424
}),
430425
);
431-
expect(validateSchema(manualSchema)).to.deep.equal([
432-
{
433-
message: 'Type IncompleteObject must define one or more fields.',
434-
},
435-
]);
426+
expect(validateSchema(manualSchema)).to.deep.equal([]);
436427

437428
const manualSchema2 = schemaWithFieldType(
438429
new GraphQLObjectType({
@@ -442,11 +433,7 @@ describe('Type System: Objects must have fields', () => {
442433
},
443434
}),
444435
);
445-
expect(validateSchema(manualSchema2)).to.deep.equal([
446-
{
447-
message: 'Type IncompleteObject must define one or more fields.',
448-
},
449-
]);
436+
expect(validateSchema(manualSchema2)).to.deep.equal([]);
450437
});
451438

452439
it('rejects an Object type with incorrectly named fields', () => {
@@ -707,7 +694,7 @@ describe('Type System: Input Objects must have fields', () => {
707694
expect(validateSchema(schema)).to.deep.equal([]);
708695
});
709696

710-
it('rejects an Input Object type with missing fields', () => {
697+
it('accepts an Input Object type with missing fields', () => {
711698
let schema = buildSchema(`
712699
type Query {
713700
field(arg: SomeInputObject): String
@@ -725,13 +712,7 @@ describe('Type System: Input Objects must have fields', () => {
725712
`),
726713
);
727714

728-
expect(validateSchema(schema)).to.deep.equal([
729-
{
730-
message:
731-
'Input Object type SomeInputObject must define one or more fields.',
732-
locations: [{ line: 6, column: 7 }, { line: 4, column: 9 }],
733-
},
734-
]);
715+
expect(validateSchema(schema)).to.deep.equal([]);
735716
});
736717

737718
it('accepts an Input Object with breakable circular reference', () => {

src/type/validate.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -267,14 +267,6 @@ function validateFields(
267267
): void {
268268
const fields = objectValues(type.getFields());
269269

270-
// Objects and Interfaces both must define one or more fields.
271-
if (fields.length === 0) {
272-
context.reportError(
273-
`Type ${type.name} must define one or more fields.`,
274-
getAllNodes(type),
275-
);
276-
}
277-
278270
for (const field of fields) {
279271
// Ensure they are named correctly.
280272
validateName(context, field);
@@ -494,13 +486,6 @@ function validateInputFields(
494486
): void {
495487
const fields = objectValues(inputObj.getFields());
496488

497-
if (fields.length === 0) {
498-
context.reportError(
499-
`Input Object type ${inputObj.name} must define one or more fields.`,
500-
getAllNodes(inputObj),
501-
);
502-
}
503-
504489
// Ensure the arguments are valid
505490
for (const field of fields) {
506491
// Ensure they are named correctly.

0 commit comments

Comments
 (0)