diff --git a/graphene_django/filter/tests/test_fields.py b/graphene_django/filter/tests/test_fields.py index 18e7f0c..6de8361 100644 --- a/graphene_django/filter/tests/test_fields.py +++ b/graphene_django/filter/tests/test_fields.py @@ -5,7 +5,7 @@ import pytest from django.db.models import TextField, Value from django.db.models.functions import Concat -from graphene import Argument, Boolean, Field, Float, ObjectType, Schema, String +from graphene import Argument, Boolean, Decimal, Field, ObjectType, Schema, String from graphene.relay import Node from graphene_django import DjangoObjectType from graphene_django.forms import GlobalIDFormField, GlobalIDMultipleChoiceField @@ -388,7 +388,7 @@ def test_filterset_descriptions(): field = DjangoFilterConnectionField(ArticleNode, filterset_class=ArticleIdFilter) max_time = field.args["max_time"] assert isinstance(max_time, Argument) - assert max_time.type == Float + assert max_time.type == Decimal assert max_time.description == "The maximum time" @@ -671,7 +671,7 @@ def test_should_query_filter_node_limit(): schema = Schema(query=Query) query = """ query NodeFilteringQuery { - allReporters(limit: 1) { + allReporters(limit: "1") { edges { node { id diff --git a/graphene_django/forms/converter.py b/graphene_django/forms/converter.py index 5d17680..9db0a77 100644 --- a/graphene_django/forms/converter.py +++ b/graphene_django/forms/converter.py @@ -1,12 +1,23 @@ from django import forms from django.core.exceptions import ImproperlyConfigured -from graphene import ID, Boolean, Float, Int, List, String, UUID, Date, DateTime, Time +from graphene import ( + Boolean, + Date, + DateTime, + Decimal, + Float, + ID, + Int, + List, + String, + Time, + UUID, +) from .forms import GlobalIDFormField, GlobalIDMultipleChoiceField from ..utils import import_single_dispatch - singledispatch = import_single_dispatch() @@ -52,6 +63,10 @@ def convert_form_field_to_nullboolean(field): @convert_form_field.register(forms.DecimalField) +def convert_field_to_decimal(field): + return Decimal(description=field.help_text, required=field.required) + + @convert_form_field.register(forms.FloatField) def convert_form_field_to_float(field): return Float(description=field.help_text, required=field.required) diff --git a/graphene_django/forms/tests/test_converter.py b/graphene_django/forms/tests/test_converter.py index ccf630f..78b315c 100644 --- a/graphene_django/forms/tests/test_converter.py +++ b/graphene_django/forms/tests/test_converter.py @@ -1,19 +1,19 @@ from django import forms from py.test import raises -import graphene from graphene import ( - String, - Int, Boolean, + Date, + DateTime, + Decimal, Float, ID, - UUID, + Int, List, NonNull, - DateTime, - Date, + String, Time, + UUID, ) from ..converter import convert_form_field @@ -97,8 +97,8 @@ def test_should_float_convert_float(): assert_conversion(forms.FloatField, Float) -def test_should_decimal_convert_float(): - assert_conversion(forms.DecimalField, Float) +def test_should_decimal_convert_decimal(): + assert_conversion(forms.DecimalField, Decimal) def test_should_multiple_choice_convert_list(): diff --git a/graphene_django/rest_framework/serializer_converter.py b/graphene_django/rest_framework/serializer_converter.py index 18f34b8..2535fe7 100644 --- a/graphene_django/rest_framework/serializer_converter.py +++ b/graphene_django/rest_framework/serializer_converter.py @@ -115,8 +115,12 @@ def convert_serializer_field_to_bool(field): return graphene.Boolean -@get_graphene_type_from_serializer_field.register(serializers.FloatField) @get_graphene_type_from_serializer_field.register(serializers.DecimalField) +def convert_serializer_field_to_decimal(field): + return graphene.Decimal + + +@get_graphene_type_from_serializer_field.register(serializers.FloatField) def convert_serializer_field_to_float(field): return graphene.Float diff --git a/graphene_django/rest_framework/tests/test_field_converter.py b/graphene_django/rest_framework/tests/test_field_converter.py index daa8349..4858365 100644 --- a/graphene_django/rest_framework/tests/test_field_converter.py +++ b/graphene_django/rest_framework/tests/test_field_converter.py @@ -133,9 +133,9 @@ def test_should_float_convert_float(): assert_conversion(serializers.FloatField, graphene.Float) -def test_should_decimal_convert_float(): +def test_should_decimal_convert_decimal(): assert_conversion( - serializers.DecimalField, graphene.Float, max_digits=4, decimal_places=2 + serializers.DecimalField, graphene.Decimal, max_digits=4, decimal_places=2 ) diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 287ec82..df3771c 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -242,7 +242,7 @@ def test_should_float_convert_float(): assert_conversion(models.FloatField, graphene.Float) -def test_should_float_convert_decimal(): +def test_should_decimal_convert_decimal(): assert_conversion(models.DecimalField, graphene.Decimal)