Fix nullability issue in construct_fields function (#34)

* Fix nullability issue in construct_fields function

* Update types.py
This commit is contained in:
arielRevo 2024-03-07 17:24:52 +01:00 committed by GitHub
parent 7e073e11e4
commit 9b4baab6b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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