Skip to content

Commit

Permalink
null default args in introspection query
Browse files Browse the repository at this point in the history
  • Loading branch information
jaemk committed Jul 12, 2018
1 parent af5976a commit 63f9f35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 4 additions & 1 deletion graphql/execution/executor.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from ..error import GraphQLError, GraphQLLocatedError
from ..pyutils.default_ordered_dict import DefaultOrderedDict
from ..pyutils.ordereddict import OrderedDict
from ..utils.undefined import Undefined
from ..utils.undefined import Undefined, UndefinedDefaultValue
from ..type import (GraphQLEnumType, GraphQLInterfaceType, GraphQLList,
GraphQLNonNull, GraphQLObjectType, GraphQLScalarType,
GraphQLSchema, GraphQLUnionType)
Expand Down Expand Up @@ -239,6 +239,9 @@ def resolve_field(exe_context, parent_type, source, field_asts, parent_info):
executor = exe_context.executor
result = resolve_or_error(resolve_fn_middleware, source, info, args, executor)

if result is UndefinedDefaultValue:
return Undefined

return complete_value_catching_error(
exe_context,
return_type,
Expand Down
14 changes: 11 additions & 3 deletions graphql/type/introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

from ..language.printer import print_ast
from ..utils.ast_from_value import ast_from_value
from ..utils.undefined import UndefinedDefaultValue
from .definition import (GraphQLArgument, GraphQLEnumType, GraphQLEnumValue,
GraphQLField, GraphQLInputObjectType,
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
Expand Down Expand Up @@ -333,6 +334,15 @@ def input_fields(type, info):
])
)


def _resolve_default_value(input_value, *_):
if input_value.default_value is UndefinedDefaultValue:
return UndefinedDefaultValue
if input_value.default_value is None:
return None
return print_ast(ast_from_value(input_value.default_value, input_value))


__InputValue = GraphQLObjectType(
'__InputValue',
description='Arguments provided to Fields or Directives and the input fields of an '
Expand All @@ -344,9 +354,7 @@ def input_fields(type, info):
('type', GraphQLField(GraphQLNonNull(__Type))),
('defaultValue', GraphQLField(
type=GraphQLString,
resolver=lambda input_val, *_:
None if input_val.default_value is None
else print_ast(ast_from_value(input_val.default_value, input_val))
resolver=_resolve_default_value,
))
]))

Expand Down
12 changes: 12 additions & 0 deletions graphql/utils/tests/test_build_client_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def test_builds_a_simple_schema_with_both_operation_types():
fields={
'setString': GraphQLField(GraphQLString, description='Set the string field', args={
'value': GraphQLArgument(GraphQLString)
}),
'setStringDefault': GraphQLField(GraphQLString, description='Set the string field', args={
'value_default': GraphQLArgument(GraphQLString, default_value=None)
})
}
)
Expand Down Expand Up @@ -387,6 +390,15 @@ def test_builds_a_schema_with_field_arguments_with_default_values():
)
}
)),
('defaultNullInt', GraphQLField(
GraphQLString,
args={
'intArg': GraphQLArgument(
GraphQLInt,
default_value=None
)
}
)),
('defaultList', GraphQLField(
GraphQLString,
args={
Expand Down

0 comments on commit 63f9f35

Please sign in to comment.