Skip to content

Commit 4132953

Browse files
committed
[RFC] Additional optional arguments
Closes #26
1 parent 68b8ad5 commit 4132953

File tree

2 files changed

+39
-6
lines changed

2 files changed

+39
-6
lines changed

graphql/core/type/schema.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,12 @@ def assert_object_implements_interface(object, interface):
159159
for object_arg in object_field.args:
160160
arg_name = object_arg.name
161161
interface_arg = interface_arg_map.get(arg_name)
162-
assert interface_arg, (
163-
'{}.{} does not define argument "{}" but {}.{} provides it.'
164-
).format(interface, field_name, arg_name, object, field_name)
162+
if not interface_arg:
163+
assert not isinstance(object_arg.type, GraphQLNonNull), (
164+
'{}.{}({}:) is of required type '
165+
'"{}" but is not also provided by the '
166+
'interface {}.{}.'
167+
).format(object, field_name, arg_name, object_arg.type, interface, field_name)
165168

166169

167170
def is_equal_type(type_a, type_b):

tests/core_type/test_validation.py

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,7 @@ def test_accepts_an_object_which_implements_an_interface_along_with_more_fields(
12881288

12891289
assert schema_with_field_type(AnotherObject)
12901290

1291-
def test_rejects_an_object_which_implements_an_interface_field_along_with_more_arguments(self):
1291+
def test_accepts_an_object_which_implements_an_interface_field_along_with_more_arguments(self):
12921292
AnotherInterface = GraphQLInterfaceType(
12931293
name='AnotherInterface',
12941294
resolve_type=_none,
@@ -1316,11 +1316,41 @@ def test_rejects_an_object_which_implements_an_interface_field_along_with_more_a
13161316
}
13171317
)
13181318

1319+
assert schema_with_field_type(AnotherObject)
1320+
1321+
def test_rejects_an_object_which_implements_an_interface_field_along_with_additional_required_arguments(self):
1322+
AnotherInterface = GraphQLInterfaceType(
1323+
name='AnotherInterface',
1324+
resolve_type=_none,
1325+
fields={
1326+
'field': GraphQLField(
1327+
type=GraphQLString,
1328+
args={
1329+
'input': GraphQLArgument(GraphQLString)
1330+
}
1331+
)
1332+
}
1333+
)
1334+
1335+
AnotherObject = GraphQLObjectType(
1336+
name='AnotherObject',
1337+
interfaces=[AnotherInterface],
1338+
fields={
1339+
'field': GraphQLField(
1340+
type=GraphQLString,
1341+
args={
1342+
'input': GraphQLArgument(GraphQLString),
1343+
'anotherInput': GraphQLArgument(GraphQLNonNull(GraphQLString)),
1344+
}
1345+
),
1346+
}
1347+
)
1348+
13191349
with raises(AssertionError) as excinfo:
13201350
schema_with_field_type(AnotherObject)
13211351

1322-
assert str(excinfo.value) == 'AnotherInterface.field does not define argument "anotherInput" but ' \
1323-
'AnotherObject.field provides it.'
1352+
assert str(excinfo.value) == 'AnotherObject.field(anotherInput:) is of required type "String!" but ' \
1353+
'is not also provided by the interface AnotherInterface.field.'
13241354

13251355
def test_rejects_an_object_missing_an_interface_field(self):
13261356
AnotherInterface = GraphQLInterfaceType(

0 commit comments

Comments
 (0)