diff --git a/graphene/contrib/django/fields.py b/graphene/contrib/django/fields.py index 0b719586..7b990b86 100644 --- a/graphene/contrib/django/fields.py +++ b/graphene/contrib/django/fields.py @@ -1,24 +1,22 @@ +import warnings + from ...core.exceptions import SkipField from ...core.fields import Field from ...core.types.base import FieldType from ...core.types.definitions import List from ...relay import ConnectionField from ...relay.utils import is_node -from .utils import get_type_for_model, lazy_map +from .utils import get_type_for_model class DjangoConnectionField(ConnectionField): - pass - -class LazyListField(Field): - - def get_type(self, schema): - return List(self.type) - - def resolver(self, instance, args, info): - resolved = super(LazyListField, self).resolver(instance, args, info) - return lazy_map(resolved, self.type) + def __init__(self, *args, **kwargs): + cls = self.__class__ + warnings.warn("Using {} will be not longer supported." + " Use relay.ConnectionField instead".format(cls.__name__), + FutureWarning) + return super(DjangoConnectionField, self).__init__(*args, **kwargs) class ConnectionOrListField(Field): @@ -31,7 +29,7 @@ class ConnectionOrListField(Field): if is_node(field_object_type): field = DjangoConnectionField(field_object_type) else: - field = LazyListField(field_object_type) + field = Field(List(field_object_type)) field.contribute_to_class(self.object_type, self.attname) return schema.T(field) diff --git a/graphene/contrib/django/types.py b/graphene/contrib/django/types.py index 8ef2a6a3..55b76fa7 100644 --- a/graphene/contrib/django/types.py +++ b/graphene/contrib/django/types.py @@ -5,7 +5,7 @@ from ...relay.fields import GlobalIDField from ...relay.types import BaseNode, Connection from .converter import convert_django_field from .options import DjangoOptions -from .utils import get_reverse_fields, lazy_map +from .utils import get_reverse_fields, maybe_queryset class DjangoObjectTypeMeta(ObjectTypeMeta): @@ -30,7 +30,7 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): is_excluded = field.name in cls._meta.exclude_fields or is_already_created if is_not_in_only or is_excluded: # We skip this field if we specify only_fields and is not - # in there. Or when we excldue this field in exclude_fields + # in there. Or when we exclude this field in exclude_fields continue converted_field = convert_django_field(field) cls.add_to_class(field.name, converted_field) @@ -74,7 +74,7 @@ class DjangoInterface(six.with_metaclass( class DjangoConnection(Connection): @classmethod def from_list(cls, iterable, *args, **kwargs): - iterable = lazy_map(iterable, cls.edge_type.node_type) + iterable = maybe_queryset(iterable) return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs) diff --git a/graphene/contrib/django/utils.py b/graphene/contrib/django/utils.py index 0d557e9a..54c6420c 100644 --- a/graphene/contrib/django/utils.py +++ b/graphene/contrib/django/utils.py @@ -1,8 +1,5 @@ from django.db import models from django.db.models.manager import Manager -from django.db.models.query import QuerySet - -from ...utils import LazyMap def get_type_for_model(schema, model): @@ -22,9 +19,7 @@ def get_reverse_fields(model): yield related -def lazy_map(value, func): +def maybe_queryset(value): if isinstance(value, Manager): value = value.get_queryset() - if isinstance(value, QuerySet): - return LazyMap(value, func) return value