From ad0b3a529cbe006284dfdb1c01d1b68b60c3cd18 Mon Sep 17 00:00:00 2001 From: Jean-Louis Fuchs Date: Sat, 8 Feb 2020 21:24:58 +0100 Subject: [PATCH] The default_value of InputField should be INVALID (#1111) * The default_value of InputField should be INVALID Since GraphQL 3.0 there is a distinction between None and INVALID (no value). The tests captured the bug and are updated. * Update minimum graphql-core version * Use Undefined instead of INVALID Co-authored-by: Jonathan Kim --- .../tests/snapshots/snap_test_objectidentification.py | 2 +- graphene/relay/tests/test_mutation.py | 4 ++-- graphene/types/inputfield.py | 3 ++- graphene/types/tests/test_query.py | 9 +++------ setup.py | 2 +- tests_asyncio/test_relay_mutation.py | 4 ++-- 6 files changed, 11 insertions(+), 13 deletions(-) diff --git a/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py b/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py index 02e61c39..e42260f8 100644 --- a/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py +++ b/examples/starwars_relay/tests/snapshots/snap_test_objectidentification.py @@ -46,7 +46,7 @@ type Faction implements Node { input IntroduceShipInput { shipName: String! factionId: String! - clientMutationId: String = null + clientMutationId: String } type IntroduceShipPayload { diff --git a/graphene/relay/tests/test_mutation.py b/graphene/relay/tests/test_mutation.py index 5fb1c468..e079ab4e 100644 --- a/graphene/relay/tests/test_mutation.py +++ b/graphene/relay/tests/test_mutation.py @@ -80,11 +80,11 @@ class OtherMutation(ClientIDMutation): @staticmethod def mutate_and_get_payload( - self, info, shared, additional_field, client_mutation_id=None + self, info, shared="", additional_field="", client_mutation_id=None ): edge_type = MyEdge return OtherMutation( - name=(shared or "") + (additional_field or ""), + name=shared + additional_field, my_node_edge=edge_type(cursor="1", node=MyNode(name="name")), ) diff --git a/graphene/types/inputfield.py b/graphene/types/inputfield.py index b0e0915a..bf3538e3 100644 --- a/graphene/types/inputfield.py +++ b/graphene/types/inputfield.py @@ -1,3 +1,4 @@ +from graphql import Undefined from .mountedtype import MountedType from .structures import NonNull from .utils import get_type @@ -48,7 +49,7 @@ class InputField(MountedType): self, type, name=None, - default_value=None, + default_value=Undefined, deprecation_reason=None, description=None, required=False, diff --git a/graphene/types/tests/test_query.py b/graphene/types/tests/test_query.py index 004d53c8..fe9f39fc 100644 --- a/graphene/types/tests/test_query.py +++ b/graphene/types/tests/test_query.py @@ -262,17 +262,14 @@ def test_query_input_field(): result = test_schema.execute('{ test(aInput: {aField: "String!"} ) }', "Source!") assert not result.errors - assert result.data == { - "test": '["Source!",{"a_input":{"a_field":"String!","recursive_field":null}}]' - } + assert result.data == {"test": '["Source!",{"a_input":{"a_field":"String!"}}]'} result = test_schema.execute( '{ test(aInput: {recursiveField: {aField: "String!"}}) }', "Source!" ) assert not result.errors assert result.data == { - "test": '["Source!",{"a_input":{"a_field":null,"recursive_field":' - '{"a_field":"String!","recursive_field":null}}}]' + "test": '["Source!",{"a_input":{"recursive_field":{"a_field":"String!"}}}]' } @@ -408,7 +405,7 @@ def test_big_list_of_containers_multiple_fields_query_benchmark(benchmark): def test_big_list_of_containers_multiple_fields_custom_resolvers_query_benchmark( - benchmark + benchmark, ): class Container(ObjectType): x = Int() diff --git a/setup.py b/setup.py index d7077f0c..977eba5d 100644 --- a/setup.py +++ b/setup.py @@ -83,7 +83,7 @@ setup( keywords="api graphql protocol rest relay graphene", packages=find_packages(exclude=["tests", "tests.*", "examples"]), install_requires=[ - "graphql-core>=3.0.0,<4", + "graphql-core>=3.0.3,<4", "graphql-relay>=3.0.0,<4", "aniso8601>=6,<9", "unidecode>=1.1.1,<2", diff --git a/tests_asyncio/test_relay_mutation.py b/tests_asyncio/test_relay_mutation.py index 7b083dbf..4308a614 100644 --- a/tests_asyncio/test_relay_mutation.py +++ b/tests_asyncio/test_relay_mutation.py @@ -42,11 +42,11 @@ class OtherMutation(ClientIDMutation): @staticmethod def mutate_and_get_payload( - self, info, shared, additional_field, client_mutation_id=None + self, info, shared="", additional_field="", client_mutation_id=None ): edge_type = MyEdge return OtherMutation( - name=(shared or "") + (additional_field or ""), + name=shared + additional_field, my_node_edge=edge_type(cursor="1", node=MyNode(name="name")), )