From 9b4baab6b6409b13b8c00727ec5ea6ae771350bf Mon Sep 17 00:00:00 2001 From: arielRevo <120393131+arielRevo@users.noreply.github.com> Date: Thu, 7 Mar 2024 17:24:52 +0100 Subject: [PATCH] Fix nullability issue in construct_fields function (#34) * Fix nullability issue in construct_fields function * Update types.py --- graphene_django/types.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/graphene_django/types.py b/graphene_django/types.py index 4565a58..96794de 100644 --- a/graphene_django/types.py +++ b/graphene_django/types.py @@ -55,7 +55,9 @@ def construct_fields( else: _convert_choices_to_enum = False + # Make Django field nullable then graphene will generate the graphql field nullable. if name != 'id' and not permission_raise_exception: + previous = field.null field.null = True converted = convert_django_field_with_choices( @@ -65,6 +67,10 @@ def construct_fields( if isinstance(converted, NonNull) and getattr(converted, '_of_type', None) == Boolean and not permission_raise_exception: converted = Boolean(description=field.help_text, required=False) + # Restore Django field nullability to original value + if name != 'id' and not permission_raise_exception: + field.null = previous + fields[name] = converted return fields