Repository: graphql-python/graphene-django

Issue:
Convert DecimalField to String rather than Float
DecimalField entries are currently being converted to Float (https://github.com/graphql-python/graphene-django/blob/8f5a425859ea380d0640c441c5c7f3b1acae17b4/graphene_django/form_converter.py#L56-L59)

Full support for Decimal would be great, but in the meantime I propose that DecimalField should be converted to String instead. Once you've converted a Decimal to a Float, you've probably lost the benefit of why you used Decimal in the first place, since you'll now have values like `3.14000000000000012`, rather than `3.14`. If it is converted to String, it is simple enough for the user to convert that String back to Decimal, whereas converting from Float to Decimal is not straightforward.

Discussion:

Patch:
diff --git a/graphene_django/converter.py b/graphene_django/converter.py
index 0de6964..63cc35d 100644
--- a/graphene_django/converter.py
+++ b/graphene_django/converter.py
@@ -18,6 +18,7 @@ from graphene import (
     DateTime,
     Date,
     Time,
+    Decimal,
 )
 from graphene.types.json import JSONString
 from graphene.utils.str_converters import to_camel_case
@@ -160,6 +161,10 @@ def convert_field_to_boolean(field, registry=None):
 
 
 @convert_django_field.register(models.DecimalField)
+def convert_field_to_decimal(field, registry=None):
+    return Decimal(description=field.help_text, required=not field.null)
+
+
 @convert_django_field.register(models.FloatField)
 @convert_django_field.register(models.DurationField)
 def convert_field_to_float(field, registry=None):


Test patch:
diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py
index 7d8e669..287ec82 100644
--- a/graphene_django/tests/test_converter.py
+++ b/graphene_django/tests/test_converter.py
@@ -242,6 +242,10 @@ def test_should_float_convert_float():
     assert_conversion(models.FloatField, graphene.Float)
 
 
+def test_should_float_convert_decimal():
+    assert_conversion(models.DecimalField, graphene.Decimal)
+
+
 def test_should_manytomany_convert_connectionorlist():
     registry = Registry()
     dynamic_field = convert_django_field(Reporter._meta.local_many_to_many[0], registry)