mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-23 23:20:47 +03:00
Fix return promise from ConnectionField resolver
This commit is contained in:
parent
17ba01570a
commit
b9f08606a0
|
@ -1,4 +1,5 @@
|
||||||
import six
|
import six
|
||||||
|
import functools
|
||||||
|
|
||||||
from graphql_relay.node.node import from_global_id
|
from graphql_relay.node.node import from_global_id
|
||||||
|
|
||||||
|
@ -8,6 +9,8 @@ from ..core.types.scalars import ID, Int, String
|
||||||
from ..utils.wrap_resolver_function import has_context, with_context
|
from ..utils.wrap_resolver_function import has_context, with_context
|
||||||
from .connection import Connection, Edge
|
from .connection import Connection, Edge
|
||||||
|
|
||||||
|
def _is_thenable(obj):
|
||||||
|
return callable(getattr(obj, "then", None))
|
||||||
|
|
||||||
class ConnectionField(Field):
|
class ConnectionField(Field):
|
||||||
|
|
||||||
|
@ -26,6 +29,11 @@ class ConnectionField(Field):
|
||||||
**kwargs)
|
**kwargs)
|
||||||
self.connection_type = connection_type or Connection
|
self.connection_type = connection_type or Connection
|
||||||
self.edge_type = edge_type or Edge
|
self.edge_type = edge_type or Edge
|
||||||
|
|
||||||
|
def _get_connection_type(self, connection_type, args, context, info, resolved):
|
||||||
|
if isinstance(resolved, self.connection_type):
|
||||||
|
return resolved
|
||||||
|
return self.from_list(connection_type, resolved, args, context, info)
|
||||||
|
|
||||||
@with_context
|
@with_context
|
||||||
def resolver(self, instance, args, context, info):
|
def resolver(self, instance, args, context, info):
|
||||||
|
@ -38,9 +46,12 @@ class ConnectionField(Field):
|
||||||
else:
|
else:
|
||||||
resolved = super(ConnectionField, self).resolver(instance, args, info)
|
resolved = super(ConnectionField, self).resolver(instance, args, info)
|
||||||
|
|
||||||
if isinstance(resolved, self.connection_type):
|
get_connection_type = functools.partial(self._get_connection_type, connection_type, args, context, info)
|
||||||
return resolved
|
|
||||||
return self.from_list(connection_type, resolved, args, context, info)
|
if _is_thenable(resolved):
|
||||||
|
return resolved.then(get_connection_type)
|
||||||
|
|
||||||
|
return get_connection_type(resolved)
|
||||||
|
|
||||||
def from_list(self, connection_type, resolved, args, context, info):
|
def from_list(self, connection_type, resolved, args, context, info):
|
||||||
return connection_type.from_list(resolved, args, context, info)
|
return connection_type.from_list(resolved, args, context, info)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user