mirror of
https://github.com/graphql-python/graphene.git
synced 2025-03-05 20:35:46 +03:00
Merge branch 'patch-11'
This commit is contained in:
commit
0b9aa7cbeb
|
@ -5,6 +5,7 @@ from functools import partial
|
||||||
import six
|
import six
|
||||||
|
|
||||||
from graphql_relay import connection_from_list
|
from graphql_relay import connection_from_list
|
||||||
|
from promise import Promise
|
||||||
|
|
||||||
from ..types import (AbstractType, Boolean, Enum, Int, Interface, List, NonNull, Scalar, String,
|
from ..types import (AbstractType, Boolean, Enum, Int, Interface, List, NonNull, Scalar, String,
|
||||||
Union)
|
Union)
|
||||||
|
@ -118,26 +119,34 @@ class IterableConnectionField(Field):
|
||||||
return connection_type
|
return connection_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def connection_resolver(cls, resolver, connection, root, args, context, info):
|
def resolve_connection(cls, connection_type, args, resolved):
|
||||||
resolved = resolver(root, args, context, info)
|
if isinstance(resolved, connection_type):
|
||||||
|
|
||||||
if isinstance(resolved, connection):
|
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
assert isinstance(resolved, Iterable), (
|
assert isinstance(resolved, Iterable), (
|
||||||
'Resolved value from the connection field have to be iterable or instance of {}. '
|
'Resolved value from the connection field have to be iterable or instance of {}. '
|
||||||
'Received "{}"'
|
'Received "{}"'
|
||||||
).format(connection, resolved)
|
).format(connection_type, resolved)
|
||||||
connection = connection_from_list(
|
connection = connection_from_list(
|
||||||
resolved,
|
resolved,
|
||||||
args,
|
args,
|
||||||
connection_type=connection,
|
connection_type=connection_type,
|
||||||
edge_type=connection.Edge,
|
edge_type=connection_type.Edge,
|
||||||
pageinfo_type=PageInfo
|
pageinfo_type=PageInfo
|
||||||
)
|
)
|
||||||
connection.iterable = resolved
|
connection.iterable = resolved
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
|
||||||
|
resolved = resolver(root, args, context, info)
|
||||||
|
|
||||||
|
on_resolve = partial(cls.resolve_connection, connection_type, args)
|
||||||
|
if isinstance(resolved, Promise):
|
||||||
|
return resolved.then(on_resolve)
|
||||||
|
|
||||||
|
return on_resolve(resolved)
|
||||||
|
|
||||||
def get_resolver(self, parent_resolver):
|
def get_resolver(self, parent_resolver):
|
||||||
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
|
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
|
||||||
return partial(self.connection_resolver, resolver, self.type)
|
return partial(self.connection_resolver, resolver, self.type)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user