diff --git a/graphql/execution/executor.py b/graphql/execution/executor.py index 31428ee6..52b10633 100644 --- a/graphql/execution/executor.py +++ b/graphql/execution/executor.py @@ -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) @@ -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, diff --git a/graphql/type/introspection.py b/graphql/type/introspection.py index 7c44ff75..ec2e9271 100644 --- a/graphql/type/introspection.py +++ b/graphql/type/introspection.py @@ -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, @@ -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 ' @@ -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, )) ])) diff --git a/graphql/utils/tests/test_build_client_schema.py b/graphql/utils/tests/test_build_client_schema.py index c2248cd7..3de45bd4 100644 --- a/graphql/utils/tests/test_build_client_schema.py +++ b/graphql/utils/tests/test_build_client_schema.py @@ -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) }) } ) @@ -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={