Skip to content

Commit 63f9f35

Browse files
committed
null default args in introspection query
1 parent af5976a commit 63f9f35

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

graphql/execution/executor.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from ..error import GraphQLError, GraphQLLocatedError
1111
from ..pyutils.default_ordered_dict import DefaultOrderedDict
1212
from ..pyutils.ordereddict import OrderedDict
13-
from ..utils.undefined import Undefined
13+
from ..utils.undefined import Undefined, UndefinedDefaultValue
1414
from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
1515
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
1616
GraphQLSchema, GraphQLUnionType)
@@ -239,6 +239,9 @@ def resolve_field(exe_context, parent_type, source, field_asts, parent_info):
239239
executor = exe_context.executor
240240
result = resolve_or_error(resolve_fn_middleware, source, info, args, executor)
241241

242+
if result is UndefinedDefaultValue:
243+
return Undefined
244+
242245
return complete_value_catching_error(
243246
exe_context,
244247
return_type,

graphql/type/introspection.py

+11-3
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
from ..language.printer import print_ast
44
from ..utils.ast_from_value import ast_from_value
5+
from ..utils.undefined import UndefinedDefaultValue
56
from .definition import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
67
GraphQLField, GraphQLInputObjectType,
78
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
@@ -333,6 +334,15 @@ def input_fields(type, info):
333334
])
334335
)
335336

337+
338+
def _resolve_default_value(input_value, *_):
339+
if input_value.default_value is UndefinedDefaultValue:
340+
return UndefinedDefaultValue
341+
if input_value.default_value is None:
342+
return None
343+
return print_ast(ast_from_value(input_value.default_value, input_value))
344+
345+
336346
__InputValue = GraphQLObjectType(
337347
'__InputValue',
338348
description='Arguments provided to Fields or Directives and the input fields of an '
@@ -344,9 +354,7 @@ def input_fields(type, info):
344354
('type', GraphQLField(GraphQLNonNull(__Type))),
345355
('defaultValue', GraphQLField(
346356
type=GraphQLString,
347-
resolver=lambda input_val, *_:
348-
None if input_val.default_value is None
349-
else print_ast(ast_from_value(input_val.default_value, input_val))
357+
resolver=_resolve_default_value,
350358
))
351359
]))
352360

graphql/utils/tests/test_build_client_schema.py

+12
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ def test_builds_a_simple_schema_with_both_operation_types():
5454
fields={
5555
'setString': GraphQLField(GraphQLString, description='Set the string field', args={
5656
'value': GraphQLArgument(GraphQLString)
57+
}),
58+
'setStringDefault': GraphQLField(GraphQLString, description='Set the string field', args={
59+
'value_default': GraphQLArgument(GraphQLString, default_value=None)
5760
})
5861
}
5962
)
@@ -387,6 +390,15 @@ def test_builds_a_schema_with_field_arguments_with_default_values():
387390
)
388391
}
389392
)),
393+
('defaultNullInt', GraphQLField(
394+
GraphQLString,
395+
args={
396+
'intArg': GraphQLArgument(
397+
GraphQLInt,
398+
default_value=None
399+
)
400+
}
401+
)),
390402
('defaultList', GraphQLField(
391403
GraphQLString,
392404
args={

0 commit comments

Comments
 (0)