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
39 changes: 36 additions & 3 deletions src/type/__tests__/validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -1463,7 +1463,7 @@ describe('Objects must adhere to Interface they implement', () => {
}).not.to.throw();
});

it('rejects an Object which implements an Interface field along with more arguments', () => {
it('accepts an Object which implements an Interface field along with additional optional arguments', () => {
expect(() => {
var AnotherInterface = new GraphQLInterfaceType({
name: 'AnotherInterface',
Expand Down Expand Up @@ -1492,10 +1492,43 @@ describe('Objects must adhere to Interface they implement', () => {
}
});

return schemaWithFieldType(AnotherObject);
}).not.to.throw();
});

it('rejects an Object which implements an Interface field along with additional required arguments', () => {
expect(() => {
var AnotherInterface = new GraphQLInterfaceType({
name: 'AnotherInterface',
resolveType: () => null,
fields: {
field: {
type: GraphQLString,
args: {
input: { type: GraphQLString },
}
}
}
});

var AnotherObject = new GraphQLObjectType({
name: 'AnotherObject',
interfaces: [ AnotherInterface ],
fields: {
field: {
type: GraphQLString,
args: {
input: { type: GraphQLString },
anotherInput: { type: new GraphQLNonNull(GraphQLString) },
}
}
}
});

return schemaWithFieldType(AnotherObject);
}).to.throw(
'AnotherInterface.field does not define argument "anotherInput" but ' +
'AnotherObject.field provides it.'
'AnotherObject.field(anotherInput:) is of required type "String!" but ' +
'is not also provided by the interface AnotherInterface.field.'
);
});

Expand Down
15 changes: 9 additions & 6 deletions src/type/schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -218,15 +218,18 @@ function assertObjectImplementsInterface(
);
});

// Assert argument set invariance.
// Assert additional arguments must not be required.
objectField.args.forEach(objectArg => {
var argName = objectArg.name;
var ifaceArg = find(ifaceField.args, arg => arg.name === argName);
invariant(
ifaceArg,
`${iface}.${fieldName} does not define argument "${argName}" but ` +
`${object}.${fieldName} provides it.`
);
if (!ifaceArg) {
invariant(
!(objectArg.type instanceof GraphQLNonNull),
`${object}.${fieldName}(${argName}:) is of required type ` +
`"${objectArg.type}" but is not also provided by the ` +
`interface ${iface}.${fieldName}.`
);
}
});
});
}
Expand Down