Repository: graphql-python/graphene-django

Issue:
Django 2.1 BooleanField(null=True) syntax not supported by DjangoObjectType
[As of Django 2.1,](https://docs.djangoproject.com/en/2.1/ref/models/fields/#django.db.models.BooleanField) the syntax `BooleanField(null=True)` is now supported by Django (in addition to the syntax NullBooleanField() but the `null=True` is ignored by `DjangoObjectType`.

This only a problem with Django 2.1.

The bug can be reproduced like

    import graphene
    from graphene_django import DjangoObjectType
    from django.db import models
    
    class Car(models.Model):
        class Meta:
            app_label = 'app'
        is_fast = models.BooleanField(null=True)
    
    class CarNode(DjangoObjectType, model=Car):
        pass
    
    class Query(graphene.ObjectType):
        car = graphene.Field(CarNode)
    
        def resolve_car(self, info):
            return Car(is_fast=None)
        
    schema = graphene.Schema(query=Query)
    result = schema.execute('{ car { isFast } }')
    
    print(result.data, result.errors)


Discussion:
A workaround for the moment is to use a `NullBooleanField` instead. 
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

I believe that's still an issue.

Resolving patch:
diff --git a/graphene_django/converter.py b/graphene_django/converter.py
--- a/graphene_django/converter.py
+++ b/graphene_django/converter.py
@@ -127,13 +127,9 @@ def convert_field_to_int(field, registry=None):
     return Int(description=field.help_text, required=not field.null)
 
 
+@convert_django_field.register(models.NullBooleanField)
 @convert_django_field.register(models.BooleanField)
 def convert_field_to_boolean(field, registry=None):
-    return NonNull(Boolean, description=field.help_text)
-
-
-@convert_django_field.register(models.NullBooleanField)
-def convert_field_to_nullboolean(field, registry=None):
     return Boolean(description=field.help_text, required=not field.null)
 
 


Test patch:
diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py
--- a/graphene_django/tests/test_converter.py
+++ b/graphene_django/tests/test_converter.py
@@ -20,12 +20,19 @@
 
 
 def assert_conversion(django_field, graphene_field, *args, **kwargs):
-    field = django_field(help_text="Custom Help Text", null=True, *args, **kwargs)
+    _kwargs = kwargs.copy()
+    if "null" not in kwargs:
+        _kwargs["null"] = True
+    field = django_field(help_text="Custom Help Text", *args, **_kwargs)
     graphene_type = convert_django_field(field)
     assert isinstance(graphene_type, graphene_field)
     field = graphene_type.Field()
     assert field.description == "Custom Help Text"
-    nonnull_field = django_field(null=False, *args, **kwargs)
+
+    _kwargs = kwargs.copy()
+    if "null" not in kwargs:
+        _kwargs["null"] = False
+    nonnull_field = django_field(*args, **_kwargs)
     if not nonnull_field.null:
         nonnull_graphene_type = convert_django_field(nonnull_field)
         nonnull_field = nonnull_graphene_type.Field()
@@ -121,7 +128,12 @@ def test_should_integer_convert_int():
 
 
 def test_should_boolean_convert_boolean():
-    field = assert_conversion(models.BooleanField, graphene.NonNull)
+    assert_conversion(models.BooleanField, graphene.Boolean, null=True)
+
+
+def test_should_boolean_convert_non_null_boolean():
+    field = assert_conversion(models.BooleanField, graphene.Boolean, null=False)
+    assert isinstance(field.type, graphene.NonNull)
     assert field.type.of_type == graphene.Boolean