Skip to content

Commit 08ffd09

Browse files
committed
[RFC] Additional optional arguments
Implements graphql/graphql-spec#110
1 parent defbb03 commit 08ffd09

File tree

2 files changed

+45
-9
lines changed

2 files changed

+45
-9
lines changed

src/type/__tests__/validation.js

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ describe('Objects must adhere to Interface they implement', () => {
14631463
}).not.to.throw();
14641464
});
14651465

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

1495+
return schemaWithFieldType(AnotherObject);
1496+
}).not.to.throw();
1497+
});
1498+
1499+
it('rejects an Object which implements an Interface field along with additional required arguments', () => {
1500+
expect(() => {
1501+
var AnotherInterface = new GraphQLInterfaceType({
1502+
name: 'AnotherInterface',
1503+
resolveType: () => null,
1504+
fields: {
1505+
field: {
1506+
type: GraphQLString,
1507+
args: {
1508+
input: { type: GraphQLString },
1509+
}
1510+
}
1511+
}
1512+
});
1513+
1514+
var AnotherObject = new GraphQLObjectType({
1515+
name: 'AnotherObject',
1516+
interfaces: [ AnotherInterface ],
1517+
fields: {
1518+
field: {
1519+
type: GraphQLString,
1520+
args: {
1521+
input: { type: GraphQLString },
1522+
anotherInput: { type: new GraphQLNonNull(GraphQLString) },
1523+
}
1524+
}
1525+
}
1526+
});
1527+
14951528
return schemaWithFieldType(AnotherObject);
14961529
}).to.throw(
1497-
'AnotherInterface.field does not define argument "anotherInput" but ' +
1498-
'AnotherObject.field provides it.'
1530+
'AnotherObject.field(anotherInput:) is of required type "String!" but ' +
1531+
'is not also provided by the interface AnotherInterface.field.'
14991532
);
15001533
});
15011534

src/type/schema.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -218,15 +218,18 @@ function assertObjectImplementsInterface(
218218
);
219219
});
220220

221-
// Assert argument set invariance.
221+
// Assert additional arguments must not be required.
222222
objectField.args.forEach(objectArg => {
223223
var argName = objectArg.name;
224224
var ifaceArg = find(ifaceField.args, arg => arg.name === argName);
225-
invariant(
226-
ifaceArg,
227-
`${iface}.${fieldName} does not define argument "${argName}" but ` +
228-
`${object}.${fieldName} provides it.`
229-
);
225+
if (!ifaceArg) {
226+
invariant(
227+
!(objectArg.type instanceof GraphQLNonNull),
228+
`${object}.${fieldName}(${argName}:) is of required type ` +
229+
`"${objectArg.type}" but is not also provided by the ` +
230+
`interface ${iface}.${fieldName}.`
231+
);
232+
}
230233
});
231234
});
232235
}

0 commit comments

Comments
 (0)