Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions graphene/types/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
GraphQLObjectType,
GraphQLSchema,
GraphQLString,
Undefined,
)
from graphql.execution import ExecutionContext
from graphql.execution.values import get_argument_values
Expand Down Expand Up @@ -313,9 +312,7 @@ def create_fields_for_type(self, graphene_type, is_input_type=False):
arg_type,
out_name=arg_name,
description=arg.description,
default_value=Undefined
if isinstance(arg.type, NonNull)
else arg.default_value,
default_value=arg.default_value,
)
subscribe = field.wrap_subscribe(
self.get_function_for_type(
Expand Down
16 changes: 16 additions & 0 deletions graphene/types/tests/test_type_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
GraphQLInputField,
GraphQLInputObjectType,
GraphQLInterfaceType,
GraphQLNonNull,
GraphQLObjectType,
GraphQLString,
)
Expand Down Expand Up @@ -94,6 +95,21 @@ def resolve_foo(self, bar):
}


def test_required_argument_with_default_value():
class MyObjectType(ObjectType):
foo = String(bar=String(required=True, default_value="x"))

type_map = create_type_map([MyObjectType])

graphql_type = type_map["MyObjectType"]
foo_field = graphql_type.fields["foo"]

bar_argument = foo_field.args["bar"]
assert bar_argument.default_value == "x"
assert isinstance(bar_argument.type, GraphQLNonNull)
assert bar_argument.type.of_type == GraphQLString


def test_dynamic_objecttype():
class MyObjectType(ObjectType):
"""Description"""
Expand Down