Skip to content

Commit ea96cd4

Browse files
committed
Allow to add optional args to fields implemented from interfaces
Replicates graphql/graphql-js@f4dee28
1 parent a3be3d1 commit ea96cd4

File tree

2 files changed

+18
-16
lines changed

2 files changed

+18
-16
lines changed

graphql/type/validate.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
GraphQLEnumType, GraphQLInputObjectType, GraphQLInterfaceType,
1010
GraphQLObjectType, GraphQLUnionType,
1111
is_enum_type, is_input_object_type, is_input_type, is_interface_type,
12-
is_named_type, is_non_null_type,
13-
is_object_type, is_output_type, is_union_type)
12+
is_named_type, is_object_type, is_output_type, is_union_type,
13+
is_required_argument)
1414
from ..utilities.assert_valid_name import is_valid_name_error
1515
from ..utilities.type_comparators import is_equal_type, is_type_sub_type_of
1616
from .directives import GraphQLDirective, is_directive
@@ -332,14 +332,12 @@ def validate_object_implements_interface(
332332
# Assert additional arguments must not be required.
333333
for arg_name, obj_arg in obj_field.args.items():
334334
iface_arg = iface_field.args.get(arg_name)
335-
if not iface_arg and is_non_null_type(obj_arg.type):
335+
if not iface_arg and is_required_argument(obj_arg):
336336
self.report_error(
337-
'Object field argument'
338-
f' {obj.name}.{field_name}({arg_name}:)'
339-
f' is of required type {obj_arg.type}'
340-
' but is not also provided by the Interface field'
341-
f' {iface.name}.{field_name}.',
342-
[get_field_arg_type_node(obj, field_name, arg_name),
337+
f'Object field {obj.name}.{field_name} includes'
338+
f' required argument {arg_name} that is missing from'
339+
f' the Interface field {iface.name}.{field_name}.',
340+
[get_field_arg_node(obj, field_name, arg_name),
343341
get_field_node(iface, field_name)])
344342

345343
def validate_union_members(self, union: GraphQLUnionType):

tests/type/test_validation.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1278,19 +1278,23 @@ def rejects_object_implementing_an_interface_field_with_additional_args():
12781278
}
12791279
12801280
interface AnotherInterface {
1281-
field(input: String): String
1281+
field(baseArg: String): String
12821282
}
12831283
12841284
type AnotherObject implements AnotherInterface {
1285-
field(input: String, anotherInput: String!): String
1285+
field(
1286+
baseArg: String,
1287+
requiredArg: String!
1288+
optionalArg1: String,
1289+
optionalArg2: String = "",
1290+
): String
12861291
}
12871292
""")
12881293
assert validate_schema(schema) == [{
1289-
'message': 'Object field argument'
1290-
' AnotherObject.field(anotherInput:) is of'
1291-
' required type String! but is not also provided'
1292-
' by the Interface field AnotherInterface.field.',
1293-
'locations': [(11, 50), (7, 15)]}]
1294+
'message': 'Object field AnotherObject.field includes required'
1295+
' argument requiredArg that is missing from the'
1296+
' Interface field AnotherInterface.field.',
1297+
'locations': [(13, 17), (7, 15)]}]
12941298

12951299
def accepts_an_object_with_an_equivalently_wrapped_interface_field_type():
12961300
schema = build_schema("""

0 commit comments

Comments
 (0)