Skip to content

Commit c08379e

Browse files
authored
Use argument's default_value regardless if the input field is required (#1326)
* Use argument's default value regardless if the input field is required * Add a test * Format code
1 parent f622f1f commit c08379e

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

graphene/types/schema.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
GraphQLObjectType,
2727
GraphQLSchema,
2828
GraphQLString,
29-
Undefined,
3029
)
3130
from graphql.execution import ExecutionContext
3231
from graphql.execution.values import get_argument_values
@@ -313,9 +312,7 @@ def create_fields_for_type(self, graphene_type, is_input_type=False):
313312
arg_type,
314313
out_name=arg_name,
315314
description=arg.description,
316-
default_value=Undefined
317-
if isinstance(arg.type, NonNull)
318-
else arg.default_value,
315+
default_value=arg.default_value,
319316
)
320317
subscribe = field.wrap_subscribe(
321318
self.get_function_for_type(

graphene/types/tests/test_type_map.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
GraphQLInputField,
77
GraphQLInputObjectType,
88
GraphQLInterfaceType,
9+
GraphQLNonNull,
910
GraphQLObjectType,
1011
GraphQLString,
1112
)
@@ -94,6 +95,21 @@ def resolve_foo(self, bar):
9495
}
9596

9697

98+
def test_required_argument_with_default_value():
99+
class MyObjectType(ObjectType):
100+
foo = String(bar=String(required=True, default_value="x"))
101+
102+
type_map = create_type_map([MyObjectType])
103+
104+
graphql_type = type_map["MyObjectType"]
105+
foo_field = graphql_type.fields["foo"]
106+
107+
bar_argument = foo_field.args["bar"]
108+
assert bar_argument.default_value == "x"
109+
assert isinstance(bar_argument.type, GraphQLNonNull)
110+
assert bar_argument.type.of_type == GraphQLString
111+
112+
97113
def test_dynamic_objecttype():
98114
class MyObjectType(ObjectType):
99115
"""Description"""

0 commit comments

Comments
 (0)