mirror of
				https://github.com/graphql-python/graphene.git
				synced 2025-10-31 07:57:26 +03:00 
			
		
		
		
	Improved relay connections
This commit is contained in:
		
							parent
							
								
									66c375bfe3
								
							
						
					
					
						commit
						a9e09dcee8
					
				|  | @ -1,12 +1,9 @@ | ||||||
| import re | import re | ||||||
| import copy | from collections import Iterable | ||||||
| from functools import partial |  | ||||||
| import six | import six | ||||||
| from graphql_relay import connection_definitions | from graphql_relay import connection_definitions, connection_from_list | ||||||
| 
 | 
 | ||||||
| from ..types.field import Field | from ..types.field import Field | ||||||
| from ..types.mutation import Mutation, MutationMeta |  | ||||||
| from ..types.interface import GrapheneInterfaceType, Interface, InterfaceTypeMeta |  | ||||||
| from ..types.objecttype import ObjectType, ObjectTypeMeta | from ..types.objecttype import ObjectType, ObjectTypeMeta | ||||||
| 
 | 
 | ||||||
| from ..utils.props import props | from ..utils.props import props | ||||||
|  | @ -47,14 +44,36 @@ class ConnectionMeta(ObjectTypeMeta): | ||||||
|                 edge_fields=edge_fields, |                 edge_fields=edge_fields, | ||||||
|                 connection_fields=local_fields, |                 connection_fields=local_fields, | ||||||
|             ) |             ) | ||||||
|  |             cls.Edge = type(edge.name, (ObjectType, ), {'Meta': type('Meta', (object,), {'graphql_type': edge})}) | ||||||
|             cls._meta.graphql_type = connection |             cls._meta.graphql_type = connection | ||||||
|         return cls |         return cls | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
| class Connection(six.with_metaclass(ConnectionMeta, ObjectType)): | class Connection(six.with_metaclass(ConnectionMeta, ObjectType)): | ||||||
|     class Meta: |     class Meta: | ||||||
|         abstract = True |         abstract = True | ||||||
| 
 | 
 | ||||||
|     resolve_node = None |     resolve_node = None | ||||||
|     resolve_cursor = None |     resolve_cursor = None | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class IterableConnectionField(Field): | ||||||
|  |     # def __init__(self, type, *args, **kwargs): | ||||||
|  |     #     if  | ||||||
|  | 
 | ||||||
|  |     def resolver(self, root, args, context, info): | ||||||
|  |         iterable = super(ConnectionField, self).resolver(root, args, context, info) | ||||||
|  |         # if isinstance(resolved, self.type.graphene) | ||||||
|  |         assert isinstance( | ||||||
|  |             iterable, Iterable), 'Resolved value from the connection field have to be iterable' | ||||||
|  |         connection = connection_from_list( | ||||||
|  |             iterable, | ||||||
|  |             args, | ||||||
|  |             connection_type=None, | ||||||
|  |             edge_type=None, | ||||||
|  |             pageinfo_type=None | ||||||
|  |         ) | ||||||
|  |         return connection | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | ConnectionField = IterableConnectionField | ||||||
|  |  | ||||||
|  | @ -1,12 +1,10 @@ | ||||||
| from functools import partial | from functools import partial | ||||||
| import copy |  | ||||||
| import six | import six | ||||||
| from graphql_relay import mutation_with_client_mutation_id | from graphql_relay import mutation_with_client_mutation_id | ||||||
| 
 | 
 | ||||||
| from ..types.mutation import Mutation, MutationMeta | from ..types.mutation import Mutation, MutationMeta | ||||||
| from ..types.inputobjecttype import GrapheneInputObjectType, InputObjectType | from ..types.inputobjecttype import InputObjectType | ||||||
| from ..types.objecttype import GrapheneObjectType | from ..types.field import Field | ||||||
| from ..types.field import Field, InputField |  | ||||||
| 
 | 
 | ||||||
| from ..utils.props import props | from ..utils.props import props | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -1,11 +1,10 @@ | ||||||
| import copy |  | ||||||
| from functools import partial | from functools import partial | ||||||
| import six | import six | ||||||
| from graphql_relay import node_definitions, from_global_id, to_global_id | from graphql_relay import node_definitions, from_global_id, to_global_id | ||||||
| 
 | 
 | ||||||
| from ..types.field import Field | from ..types.field import Field | ||||||
| from ..types.objecttype import ObjectTypeMeta | from ..types.objecttype import ObjectTypeMeta | ||||||
| from ..types.interface import GrapheneInterfaceType, Interface, InterfaceTypeMeta | from ..types.interface import Interface | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class NodeMeta(ObjectTypeMeta): | class NodeMeta(ObjectTypeMeta): | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	Block a user