mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 20:54:16 +03:00
Improved connection abstraction
This commit is contained in:
parent
12f264b290
commit
12ffb027fa
|
@ -1,5 +1,6 @@
|
||||||
import re
|
import re
|
||||||
import copy
|
import copy
|
||||||
|
from functools import partial
|
||||||
from collections import Iterable, OrderedDict
|
from collections import Iterable, OrderedDict
|
||||||
|
|
||||||
import six
|
import six
|
||||||
|
@ -103,22 +104,25 @@ class IterableConnectionField(Field):
|
||||||
assert issubclass(connection_type, Connection), '{} type have to be a subclass of Connection'.format(str(self))
|
assert issubclass(connection_type, Connection), '{} type have to be a subclass of Connection'.format(str(self))
|
||||||
return connection_type
|
return connection_type
|
||||||
|
|
||||||
def connection_resolver(self, root, args, context, info):
|
@staticmethod
|
||||||
iterable = super(ConnectionField, self).resolver(root, args, context, info)
|
def connection_resolver(resolver, connection, root, args, context, info):
|
||||||
|
iterable = resolver(root, args, context, info)
|
||||||
# if isinstance(resolved, self.type.graphene)
|
# if isinstance(resolved, self.type.graphene)
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
iterable, Iterable), 'Resolved value from the connection field have to be iterable. Received "{}"'.format(iterable)
|
iterable, Iterable), 'Resolved value from the connection field have to be iterable. Received "{}"'.format(iterable)
|
||||||
connection = connection_from_list(
|
connection = connection_from_list(
|
||||||
iterable,
|
iterable,
|
||||||
args,
|
args,
|
||||||
connection_type=self.connection,
|
connection_type=connection,
|
||||||
edge_type=self.connection.Edge,
|
edge_type=connection.Edge,
|
||||||
)
|
)
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def resolver(self):
|
def resolver(self):
|
||||||
return self.connection_resolver
|
resolver = super(ConnectionField, self).resolver
|
||||||
|
connection = self.connection
|
||||||
|
return partial(self.connection_resolver, resolver, connection)
|
||||||
|
|
||||||
@resolver.setter
|
@resolver.setter
|
||||||
def resolver(self, resolver):
|
def resolver(self, resolver):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user