Skip to content

Commit 0b9aa7c

Browse files
committed
Merge branch 'patch-11'
2 parents ecdfed2 + 760ccc8 commit 0b9aa7c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

graphene/relay/connection.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import six
66

77
from graphql_relay import connection_from_list
8+
from promise import Promise
89

910
from ..types import (AbstractType, Boolean, Enum, Int, Interface, List, NonNull, Scalar, String,
1011
Union)
@@ -118,26 +119,34 @@ def type(self):
118119
return connection_type
119120

120121
@classmethod
121-
def connection_resolver(cls, resolver, connection, root, args, context, info):
122-
resolved = resolver(root, args, context, info)
123-
124-
if isinstance(resolved, connection):
122+
def resolve_connection(cls, connection_type, args, resolved):
123+
if isinstance(resolved, connection_type):
125124
return resolved
126125

127126
assert isinstance(resolved, Iterable), (
128127
'Resolved value from the connection field have to be iterable or instance of {}. '
129128
'Received "{}"'
130-
).format(connection, resolved)
129+
).format(connection_type, resolved)
131130
connection = connection_from_list(
132131
resolved,
133132
args,
134-
connection_type=connection,
135-
edge_type=connection.Edge,
133+
connection_type=connection_type,
134+
edge_type=connection_type.Edge,
136135
pageinfo_type=PageInfo
137136
)
138137
connection.iterable = resolved
139138
return connection
140139

140+
@classmethod
141+
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
142+
resolved = resolver(root, args, context, info)
143+
144+
on_resolve = partial(cls.resolve_connection, connection_type, args)
145+
if isinstance(resolved, Promise):
146+
return resolved.then(on_resolve)
147+
148+
return on_resolve(resolved)
149+
141150
def get_resolver(self, parent_resolver):
142151
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
143152
return partial(self.connection_resolver, resolver, self.type)

0 commit comments

Comments
 (0)