From 8fa8aea3c01d1f27babdfe0ff3288e515f56fdb1 Mon Sep 17 00:00:00 2001 From: Dulmandakh Date: Wed, 7 Jun 2023 22:36:29 +0800 Subject: [PATCH] remove JSONField compat (#1421) * remove JSONFIeld compat * fix black --- graphene_django/compat.py | 11 +---------- graphene_django/converter.py | 7 +++---- graphene_django/tests/test_converter.py | 12 ------------ graphene_django/tests/test_query.py | 3 +-- 4 files changed, 5 insertions(+), 28 deletions(-) diff --git a/graphene_django/compat.py b/graphene_django/compat.py index b0e4753..8fccdb0 100644 --- a/graphene_django/compat.py +++ b/graphene_django/compat.py @@ -10,16 +10,7 @@ try: IntegerRangeField, ArrayField, HStoreField, - JSONField as PGJSONField, RangeField, ) except ImportError: - IntegerRangeField, ArrayField, HStoreField, PGJSONField, RangeField = ( - MissingType, - ) * 5 - -try: - # JSONField is only available from Django 3.1 - from django.db.models import JSONField -except ImportError: - JSONField = MissingType + IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 5 diff --git a/graphene_django/converter.py b/graphene_django/converter.py index 375d683..a43cff7 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -35,7 +35,7 @@ except ImportError: from graphql import assert_valid_name as assert_name from graphql.pyutils import register_description -from .compat import ArrayField, HStoreField, JSONField, PGJSONField, RangeField +from .compat import ArrayField, HStoreField, RangeField from .fields import DjangoListField, DjangoConnectionField from .settings import graphene_settings from .utils.str_converters import to_const @@ -346,9 +346,8 @@ def convert_postgres_array_to_list(field, registry=None): @convert_django_field.register(HStoreField) -@convert_django_field.register(PGJSONField) -@convert_django_field.register(JSONField) -def convert_pg_and_json_field_to_string(field, registry=None): +@convert_django_field.register(models.JSONField) +def convert_json_field_to_string(field, registry=None): return JSONString( description=get_django_field_description(field), required=not field.null ) diff --git a/graphene_django/tests/test_converter.py b/graphene_django/tests/test_converter.py index 4996505..7f4e350 100644 --- a/graphene_django/tests/test_converter.py +++ b/graphene_django/tests/test_converter.py @@ -15,8 +15,6 @@ from graphene.types.scalars import BigInt from ..compat import ( ArrayField, HStoreField, - JSONField, - PGJSONField, MissingType, RangeField, ) @@ -372,16 +370,6 @@ def test_should_postgres_hstore_convert_string(): assert_conversion(HStoreField, JSONString) -@pytest.mark.skipif(PGJSONField is MissingType, reason="PGJSONField should exist") -def test_should_postgres_json_convert_string(): - assert_conversion(PGJSONField, JSONString) - - -@pytest.mark.skipif(JSONField is MissingType, reason="JSONField should exist") -def test_should_json_convert_string(): - assert_conversion(JSONField, JSONString) - - @pytest.mark.skipif(RangeField is MissingType, reason="RangeField should exist") def test_should_postgres_range_convert_list(): from django.contrib.postgres.fields import IntegerRangeField diff --git a/graphene_django/tests/test_query.py b/graphene_django/tests/test_query.py index 383ff2e..68bdc7d 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -119,13 +119,12 @@ def test_should_query_postgres_fields(): from django.contrib.postgres.fields import ( IntegerRangeField, ArrayField, - JSONField, HStoreField, ) class Event(models.Model): ages = IntegerRangeField(help_text="The age ranges") - data = JSONField(help_text="Data") + data = models.JSONField(help_text="Data") store = HStoreField() tags = ArrayField(models.CharField(max_length=50))