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 functools
|
||||
|
||||
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 .connection import Connection, Edge
|
||||
|
||||
def _is_thenable(obj):
|
||||
return callable(getattr(obj, "then", None))
|
||||
|
||||
class ConnectionField(Field):
|
||||
|
||||
|
@ -27,6 +30,11 @@ class ConnectionField(Field):
|
|||
self.connection_type = connection_type or Connection
|
||||
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
|
||||
def resolver(self, instance, args, context, info):
|
||||
schema = info.schema.graphene_schema
|
||||
|
@ -38,9 +46,12 @@ class ConnectionField(Field):
|
|||
else:
|
||||
resolved = super(ConnectionField, self).resolver(instance, args, info)
|
||||
|
||||
if isinstance(resolved, self.connection_type):
|
||||
return resolved
|
||||
return self.from_list(connection_type, resolved, args, context, info)
|
||||
get_connection_type = functools.partial(self._get_connection_type, connection_type, 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):
|
||||
return connection_type.from_list(resolved, args, context, info)
|
||||
|
|
Loading…
Reference in New Issue
Block a user