diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dfc5194..036b2ab 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -11,6 +11,10 @@ jobs: django: ["3.2", "4.1", "4.2"] python-version: ["3.8", "3.9", "3.10"] include: + - django: "2.2" + python-version: "3.10" + - django: "2.2" + python-version: "3.11" - django: "3.2" python-version: "3.7" - django: "4.1" diff --git a/graphene_django/compat.py b/graphene_django/compat.py index 4b48f03..9992def 100644 --- a/graphene_django/compat.py +++ b/graphene_django/compat.py @@ -1,9 +1,3 @@ -# For backwards compatibility, we import JSONField to have it available for import via -# this compat module (https://github.com/graphql-python/graphene-django/issues/1428). -# Django's JSONField is available in Django 3.2+ (the minimum version we support) -from django.db.models import JSONField - - class MissingType: def __init__(self, *args, **kwargs): pass @@ -18,5 +12,12 @@ try: HStoreField, RangeField, ) + + try: + from django.db.models import JSONField + except ImportError: + from django.contrib.postgres.fields import JSONField except ImportError: - IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 4 + IntegerRangeField, ArrayField, HStoreField, RangeField, JSONField = ( + MissingType, + ) * 5 diff --git a/graphene_django/converter.py b/graphene_django/converter.py index f27119a..bdf7338 100644 --- a/graphene_django/converter.py +++ b/graphene_django/converter.py @@ -37,7 +37,7 @@ except ImportError: from graphql import assert_valid_name as assert_name from graphql.pyutils import register_description -from .compat import ArrayField, HStoreField, RangeField +from .compat import ArrayField, HStoreField, RangeField, JSONField from .fields import DjangoListField, DjangoConnectionField from .settings import graphene_settings from .utils.str_converters import to_const @@ -471,7 +471,7 @@ def convert_postgres_array_to_list(field, registry=None): @convert_django_field.register(HStoreField) -@convert_django_field.register(models.JSONField) +@convert_django_field.register(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_query.py b/graphene_django/tests/test_query.py index 6ddbff2..b94b776 100644 --- a/graphene_django/tests/test_query.py +++ b/graphene_django/tests/test_query.py @@ -11,7 +11,7 @@ from pytest import raises import graphene from graphene.relay import Node -from ..compat import IntegerRangeField, MissingType +from ..compat import IntegerRangeField, MissingType, JSONField from ..fields import DjangoConnectionField from ..types import DjangoObjectType from ..utils import DJANGO_FILTER_INSTALLED @@ -133,7 +133,7 @@ def test_should_query_postgres_fields(): class Event(models.Model): ages = IntegerRangeField(help_text="The age ranges") - data = models.JSONField(help_text="Data") + data = JSONField(help_text="Data") store = HStoreField() tags = ArrayField(models.CharField(max_length=50)) diff --git a/setup.py b/setup.py index 2206d94..c186bd1 100644 --- a/setup.py +++ b/setup.py @@ -20,7 +20,7 @@ tests_require = [ "coveralls", "mock", "pytz", - "django-filter>=22.1", + "django-filter>=21.1", "pytest-django>=4.5.2", ] + rest_framework_require @@ -65,7 +65,7 @@ setup( "graphene @ git+https://github.com/graphql-python/graphene.git@ee1ff975d71f6590eb6933d76d12054c9839774a#egg=graphene", "graphql-core>=3.1.0,<4", "graphql-relay @ git+https://github.com/loft-orbital/graphql-relay-py.git@loft-v3.2.0-1#egg=graphql-relay", - "Django>=3.2", + "Django>=2.2.13", "promise>=2.1", "text-unidecode", ], diff --git a/tox.ini b/tox.ini index 9739b1c..dc7c3e1 100644 --- a/tox.ini +++ b/tox.ini @@ -1,5 +1,6 @@ [tox] envlist = + py{37,38,39,310}-django22, py{37,38,39,310}-django32, py{38,39,310}-django{41,42,main}, py311-django{41,42,main} @@ -15,6 +16,7 @@ python = [gh-actions:env] DJANGO = + 2.2: django22 3.2: django32 4.1: django41 4.2: django42 @@ -29,6 +31,7 @@ setenv = deps = -e.[test] psycopg2-binary + django22: Django==2.2.13 django32: Django>=3.2,<4.0 django41: Django>=4.1,<4.2 django42: Django>=4.2,<4.3