From a5e06525856ab92b0eef4e64600d3c3aa97d56be Mon Sep 17 00:00:00 2001 From: Jonathan Kim Date: Tue, 30 Jun 2020 13:40:08 +0100 Subject: [PATCH] Add test to confirm default_value setting --- graphene/types/tests/test_inputfield.py | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/graphene/types/tests/test_inputfield.py b/graphene/types/tests/test_inputfield.py index bfedfb05..139b2250 100644 --- a/graphene/types/tests/test_inputfield.py +++ b/graphene/types/tests/test_inputfield.py @@ -1,7 +1,12 @@ from functools import partial from ..inputfield import InputField +from ..inputobjecttype import InputObjectType +from ..scalars import String, Boolean +from ..objecttype import ObjectType from ..structures import NonNull +from ..schema import Schema +from ..mutation import Mutation from .utils import MyLazyType @@ -27,3 +32,36 @@ def test_inputfield_with_lazy_partial_type(): def test_inputfield_with_string_type(): field = InputField("graphene.types.tests.utils.MyLazyType") assert field.type == MyLazyType + + +def test_inputfield_with_default_value(): + class MyInput(InputObjectType): + name = InputField(String, default_value="Emma", required=True) + good_person = InputField(Boolean, default_value=True, required=True) + + class Query(ObjectType): + a = String() + + class TestMutation(Mutation): + class Arguments: + my_field = MyInput(required=True) + + Output = Boolean + + def mutate(root, info, my_field): + return my_field.good_person + + class MyMutation(ObjectType): + test_mutation = TestMutation.Field(required=True) + + schema = Schema(query=Query, mutation=MyMutation) + result = schema.execute( + """ + mutation { + testMutation(myField: {}) + } + """ + ) + + assert not result.errors + assert result.data == {"testMutation": True}