mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-11-01 00:17:26 +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.exceptions import SkipField | ||||||
| from ...core.fields import Field | from ...core.fields import Field | ||||||
| from ...core.types.base import FieldType | from ...core.types.base import FieldType | ||||||
| from ...core.types.definitions import List | from ...core.types.definitions import List | ||||||
| from ...relay import ConnectionField | from ...relay import ConnectionField | ||||||
| from ...relay.utils import is_node | 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): | class DjangoConnectionField(ConnectionField): | ||||||
|     pass |  | ||||||
| 
 | 
 | ||||||
| 
 |     def __init__(self, *args, **kwargs): | ||||||
| class LazyListField(Field): |         cls = self.__class__ | ||||||
| 
 |         warnings.warn("Using {} will be not longer supported." | ||||||
|     def get_type(self, schema): |                       " Use relay.ConnectionField instead".format(cls.__name__), | ||||||
|         return List(self.type) |                       FutureWarning) | ||||||
| 
 |         return super(DjangoConnectionField, self).__init__(*args, **kwargs) | ||||||
|     def resolver(self, instance, args, info): |  | ||||||
|         resolved = super(LazyListField, self).resolver(instance, args, info) |  | ||||||
|         return lazy_map(resolved, self.type) |  | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class ConnectionOrListField(Field): | class ConnectionOrListField(Field): | ||||||
|  | @ -31,7 +29,7 @@ class ConnectionOrListField(Field): | ||||||
|         if is_node(field_object_type): |         if is_node(field_object_type): | ||||||
|             field = DjangoConnectionField(field_object_type) |             field = DjangoConnectionField(field_object_type) | ||||||
|         else: |         else: | ||||||
|             field = LazyListField(field_object_type) |             field = Field(List(field_object_type)) | ||||||
|         field.contribute_to_class(self.object_type, self.attname) |         field.contribute_to_class(self.object_type, self.attname) | ||||||
|         return schema.T(field) |         return schema.T(field) | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -5,7 +5,7 @@ from ...relay.fields import GlobalIDField | ||||||
| from ...relay.types import BaseNode, Connection | from ...relay.types import BaseNode, Connection | ||||||
| from .converter import convert_django_field | from .converter import convert_django_field | ||||||
| from .options import DjangoOptions | from .options import DjangoOptions | ||||||
| from .utils import get_reverse_fields, lazy_map | from .utils import get_reverse_fields, maybe_queryset | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class DjangoObjectTypeMeta(ObjectTypeMeta): | class DjangoObjectTypeMeta(ObjectTypeMeta): | ||||||
|  | @ -30,7 +30,7 @@ class DjangoObjectTypeMeta(ObjectTypeMeta): | ||||||
|             is_excluded = field.name in cls._meta.exclude_fields or is_already_created |             is_excluded = field.name in cls._meta.exclude_fields or is_already_created | ||||||
|             if is_not_in_only or is_excluded: |             if is_not_in_only or is_excluded: | ||||||
|                 # We skip this field if we specify only_fields and is not |                 # 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 |                 continue | ||||||
|             converted_field = convert_django_field(field) |             converted_field = convert_django_field(field) | ||||||
|             cls.add_to_class(field.name, converted_field) |             cls.add_to_class(field.name, converted_field) | ||||||
|  | @ -74,7 +74,7 @@ class DjangoInterface(six.with_metaclass( | ||||||
| class DjangoConnection(Connection): | class DjangoConnection(Connection): | ||||||
|     @classmethod |     @classmethod | ||||||
|     def from_list(cls, iterable, *args, **kwargs): |     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) |         return super(DjangoConnection, cls).from_list(iterable, *args, **kwargs) | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,8 +1,5 @@ | ||||||
| from django.db import models | from django.db import models | ||||||
| from django.db.models.manager import Manager | 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): | def get_type_for_model(schema, model): | ||||||
|  | @ -22,9 +19,7 @@ def get_reverse_fields(model): | ||||||
|             yield related |             yield related | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| def lazy_map(value, func): | def maybe_queryset(value): | ||||||
|     if isinstance(value, Manager): |     if isinstance(value, Manager): | ||||||
|         value = value.get_queryset() |         value = value.get_queryset() | ||||||
|     if isinstance(value, QuerySet): |  | ||||||
|         return LazyMap(value, func) |  | ||||||
|     return value |     return value | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user