Skip to content

Commit 2d0b9dd

Browse files
authored
improvement: convert decimal field to graphene decimal (#1083)
1 parent e559a42 commit 2d0b9dd

File tree

2 files changed

+9
-0
lines changed

2 files changed

+9
-0
lines changed

graphene_django/converter.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
DateTime,
1919
Date,
2020
Time,
21+
Decimal,
2122
)
2223
from graphene.types.json import JSONString
2324
from graphene.utils.str_converters import to_camel_case
@@ -160,6 +161,10 @@ def convert_field_to_boolean(field, registry=None):
160161

161162

162163
@convert_django_field.register(models.DecimalField)
164+
def convert_field_to_decimal(field, registry=None):
165+
return Decimal(description=field.help_text, required=not field.null)
166+
167+
163168
@convert_django_field.register(models.FloatField)
164169
@convert_django_field.register(models.DurationField)
165170
def convert_field_to_float(field, registry=None):

graphene_django/tests/test_converter.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,6 +242,10 @@ def test_should_float_convert_float():
242242
assert_conversion(models.FloatField, graphene.Float)
243243

244244

245+
def test_should_float_convert_decimal():
246+
assert_conversion(models.DecimalField, graphene.Decimal)
247+
248+
245249
def test_should_manytomany_convert_connectionorlist():
246250
registry = Registry()
247251
dynamic_field = convert_django_field(Reporter._meta.local_many_to_many[0], registry)

0 commit comments

Comments
 (0)