mirror of
https://github.com/graphql-python/graphene-django.git
synced 2024-11-10 19:57:15 +03:00
parent
c925a32dc3
commit
8fa8aea3c0
|
@ -10,16 +10,7 @@ try:
|
||||||
IntegerRangeField,
|
IntegerRangeField,
|
||||||
ArrayField,
|
ArrayField,
|
||||||
HStoreField,
|
HStoreField,
|
||||||
JSONField as PGJSONField,
|
|
||||||
RangeField,
|
RangeField,
|
||||||
)
|
)
|
||||||
except ImportError:
|
except ImportError:
|
||||||
IntegerRangeField, ArrayField, HStoreField, PGJSONField, RangeField = (
|
IntegerRangeField, ArrayField, HStoreField, RangeField = (MissingType,) * 5
|
||||||
MissingType,
|
|
||||||
) * 5
|
|
||||||
|
|
||||||
try:
|
|
||||||
# JSONField is only available from Django 3.1
|
|
||||||
from django.db.models import JSONField
|
|
||||||
except ImportError:
|
|
||||||
JSONField = MissingType
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ except ImportError:
|
||||||
from graphql import assert_valid_name as assert_name
|
from graphql import assert_valid_name as assert_name
|
||||||
from graphql.pyutils import register_description
|
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 .fields import DjangoListField, DjangoConnectionField
|
||||||
from .settings import graphene_settings
|
from .settings import graphene_settings
|
||||||
from .utils.str_converters import to_const
|
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(HStoreField)
|
||||||
@convert_django_field.register(PGJSONField)
|
@convert_django_field.register(models.JSONField)
|
||||||
@convert_django_field.register(JSONField)
|
def convert_json_field_to_string(field, registry=None):
|
||||||
def convert_pg_and_json_field_to_string(field, registry=None):
|
|
||||||
return JSONString(
|
return JSONString(
|
||||||
description=get_django_field_description(field), required=not field.null
|
description=get_django_field_description(field), required=not field.null
|
||||||
)
|
)
|
||||||
|
|
|
@ -15,8 +15,6 @@ from graphene.types.scalars import BigInt
|
||||||
from ..compat import (
|
from ..compat import (
|
||||||
ArrayField,
|
ArrayField,
|
||||||
HStoreField,
|
HStoreField,
|
||||||
JSONField,
|
|
||||||
PGJSONField,
|
|
||||||
MissingType,
|
MissingType,
|
||||||
RangeField,
|
RangeField,
|
||||||
)
|
)
|
||||||
|
@ -372,16 +370,6 @@ def test_should_postgres_hstore_convert_string():
|
||||||
assert_conversion(HStoreField, JSONString)
|
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")
|
@pytest.mark.skipif(RangeField is MissingType, reason="RangeField should exist")
|
||||||
def test_should_postgres_range_convert_list():
|
def test_should_postgres_range_convert_list():
|
||||||
from django.contrib.postgres.fields import IntegerRangeField
|
from django.contrib.postgres.fields import IntegerRangeField
|
||||||
|
|
|
@ -119,13 +119,12 @@ def test_should_query_postgres_fields():
|
||||||
from django.contrib.postgres.fields import (
|
from django.contrib.postgres.fields import (
|
||||||
IntegerRangeField,
|
IntegerRangeField,
|
||||||
ArrayField,
|
ArrayField,
|
||||||
JSONField,
|
|
||||||
HStoreField,
|
HStoreField,
|
||||||
)
|
)
|
||||||
|
|
||||||
class Event(models.Model):
|
class Event(models.Model):
|
||||||
ages = IntegerRangeField(help_text="The age ranges")
|
ages = IntegerRangeField(help_text="The age ranges")
|
||||||
data = JSONField(help_text="Data")
|
data = models.JSONField(help_text="Data")
|
||||||
store = HStoreField()
|
store = HStoreField()
|
||||||
tags = ArrayField(models.CharField(max_length=50))
|
tags = ArrayField(models.CharField(max_length=50))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user