mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 04:34:13 +03:00
Simplified Django grapheme types removing LazyMap
This commit is contained in:
parent
732b1aec1b
commit
c521e181c8
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user