Skip to content

Commit

Permalink
Allow interfaces to have no implementors (#1376)
Browse files Browse the repository at this point in the history
* Allow interfaces to have no implementors
Reverts #1277, and implements spec removal from #459. While it's an open question whether this validation is good, we need to provide an upgrade path for schemas that currently do not satisfy this validation rule.

* Update test to accept unimplemented interface
  • Loading branch information
mjmahone committed Jun 8, 2018
1 parent 409d6dd commit 9925e50
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
10 changes: 2 additions & 8 deletions src/type/__tests__/validation-test.js
Expand Up @@ -1205,7 +1205,7 @@ describe('Type System: Interface fields must have output types', () => {
]);
});

it('rejects an interface not implemented by at least one object', () => {
it('accepts an interface not implemented by at least one object', () => {
const schema = buildSchema(`
type Query {
test: SomeInterface
Expand All @@ -1215,13 +1215,7 @@ describe('Type System: Interface fields must have output types', () => {
foo: String
}
`);
expect(validateSchema(schema)).to.deep.equal([
{
message:
'Interface SomeInterface must be implemented by at least one Object type.',
locations: [{ line: 6, column: 7 }],
},
]);
expect(validateSchema(schema)).to.deep.equal([]);
});
});

Expand Down
18 changes: 0 additions & 18 deletions src/type/validate.js
Expand Up @@ -257,9 +257,6 @@ function validateTypes(context: SchemaValidationContext): void {
} else if (isInterfaceType(type)) {
// Ensure fields are valid.
validateFields(context, type);

// Ensure Interfaces include at least 1 Object type.
validateInterfaces(context, type);
} else if (isUnionType(type)) {
// Ensure Unions include valid member types.
validateUnionMembers(context, type);
Expand Down Expand Up @@ -367,21 +364,6 @@ function validateObjectInterfaces(
});
}

function validateInterfaces(
context: SchemaValidationContext,
iface: GraphQLInterfaceType,
): void {
const possibleTypes = context.schema.getPossibleTypes(iface);

if (possibleTypes.length === 0) {
context.reportError(
`Interface ${iface.name} must be implemented ` +
`by at least one Object type.`,
iface.astNode,
);
}
}

function validateObjectImplementsInterface(
context: SchemaValidationContext,
object: GraphQLObjectType,
Expand Down

0 comments on commit 9925e50

Please sign in to comment.