Skip to content

Commit 894c564

Browse files
authored
Convert nullable BooleanField to nullable Boolean. (#777)
1 parent b8d8508 commit 894c564

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

graphene_django/converter.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,13 +152,9 @@ def convert_field_to_int(field, registry=None):
152152
return Int(description=field.help_text, required=not field.null)
153153

154154

155+
@convert_django_field.register(models.NullBooleanField)
155156
@convert_django_field.register(models.BooleanField)
156157
def convert_field_to_boolean(field, registry=None):
157-
return NonNull(Boolean, description=field.help_text)
158-
159-
160-
@convert_django_field.register(models.NullBooleanField)
161-
def convert_field_to_nullboolean(field, registry=None):
162158
return Boolean(description=field.help_text, required=not field.null)
163159

164160

graphene_django/tests/test_converter.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,19 @@
2525

2626

2727
def assert_conversion(django_field, graphene_field, *args, **kwargs):
28-
field = django_field(help_text="Custom Help Text", null=True, *args, **kwargs)
28+
_kwargs = kwargs.copy()
29+
if "null" not in kwargs:
30+
_kwargs["null"] = True
31+
field = django_field(help_text="Custom Help Text", *args, **_kwargs)
2932
graphene_type = convert_django_field(field)
3033
assert isinstance(graphene_type, graphene_field)
3134
field = graphene_type.Field()
3235
assert field.description == "Custom Help Text"
33-
nonnull_field = django_field(null=False, *args, **kwargs)
36+
37+
_kwargs = kwargs.copy()
38+
if "null" not in kwargs:
39+
_kwargs["null"] = False
40+
nonnull_field = django_field(*args, **_kwargs)
3441
if not nonnull_field.null:
3542
nonnull_graphene_type = convert_django_field(nonnull_field)
3643
nonnull_field = nonnull_graphene_type.Field()
@@ -126,7 +133,12 @@ def test_should_integer_convert_int():
126133

127134

128135
def test_should_boolean_convert_boolean():
129-
field = assert_conversion(models.BooleanField, graphene.NonNull)
136+
assert_conversion(models.BooleanField, graphene.Boolean, null=True)
137+
138+
139+
def test_should_boolean_convert_non_null_boolean():
140+
field = assert_conversion(models.BooleanField, graphene.Boolean, null=False)
141+
assert isinstance(field.type, graphene.NonNull)
130142
assert field.type.of_type == graphene.Boolean
131143

132144

0 commit comments

Comments
 (0)