Skip to content

Commit f4dee28

Browse files
Allow to add optional args to fields implemented from interfaces (#1493)
I reviewed all `isNonNullType` calls and it the last one that needs to be fixed to complete #1274
1 parent 0adece9 commit f4dee28

File tree

2 files changed

+17
-12
lines changed

2 files changed

+17
-12
lines changed

src/type/__tests__/validation-test.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1703,20 +1703,25 @@ describe('Objects must adhere to Interface they implement', () => {
17031703
}
17041704
17051705
interface AnotherInterface {
1706-
field(input: String): String
1706+
field(baseArg: String): String
17071707
}
17081708
17091709
type AnotherObject implements AnotherInterface {
1710-
field(input: String, anotherInput: String!): String
1710+
field(
1711+
baseArg: String,
1712+
requiredArg: String!
1713+
optionalArg1: String,
1714+
optionalArg2: String = "",
1715+
): String
17111716
}
17121717
`);
17131718
expect(validateSchema(schema)).to.deep.equal([
17141719
{
17151720
message:
1716-
'Object field argument AnotherObject.field(anotherInput:) is of ' +
1717-
'required type String! but is not also provided by the Interface ' +
1718-
'field AnotherInterface.field.',
1719-
locations: [{ line: 11, column: 44 }, { line: 7, column: 9 }],
1721+
'Object field AnotherObject.field includes required argument ' +
1722+
'requiredArg that is missing from the Interface field ' +
1723+
'AnotherInterface.field.',
1724+
locations: [{ line: 13, column: 11 }, { line: 7, column: 9 }],
17201725
},
17211726
]);
17221727
});

src/type/validate.js

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ import {
1313
isUnionType,
1414
isEnumType,
1515
isInputObjectType,
16-
isNonNullType,
1716
isNamedType,
1817
isInputType,
1918
isOutputType,
19+
isRequiredArgument,
2020
} from './definition';
2121
import type {
2222
GraphQLObjectType,
@@ -438,13 +438,13 @@ function validateObjectImplementsInterface(
438438
for (const objectArg of objectField.args) {
439439
const argName = objectArg.name;
440440
const ifaceArg = find(ifaceField.args, arg => arg.name === argName);
441-
if (!ifaceArg && isNonNullType(objectArg.type)) {
441+
if (!ifaceArg && isRequiredArgument(objectArg)) {
442442
context.reportError(
443-
`Object field argument ${object.name}.${fieldName}(${argName}:) ` +
444-
`is of required type ${inspect(objectArg.type)} but is not also ` +
445-
`provided by the Interface field ${iface.name}.${fieldName}.`,
443+
`Object field ${object.name}.${fieldName} includes required ` +
444+
`argument ${argName} that is missing from the Interface field ` +
445+
`${iface.name}.${fieldName}.`,
446446
[
447-
getFieldArgTypeNode(object, fieldName, argName),
447+
getFieldArgNode(object, fieldName, argName),
448448
getFieldNode(iface, fieldName),
449449
],
450450
);

0 commit comments

Comments
 (0)