Skip to content

Commit ea69be6

Browse files
authored
Add support to return a promise for connections.
1 parent 0a80119 commit ea69be6

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

graphene/relay/connection.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -118,25 +118,28 @@ def type(self):
118118
return connection_type
119119

120120
@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):
125-
return resolved
126-
127-
assert isinstance(resolved, Iterable), (
128-
'Resolved value from the connection field have to be iterable or instance of {}. '
129-
'Received "{}"'
130-
).format(connection, resolved)
131-
connection = connection_from_list(
132-
resolved,
133-
args,
134-
connection_type=connection,
135-
edge_type=connection.Edge,
136-
pageinfo_type=PageInfo
137-
)
138-
connection.iterable = resolved
139-
return connection
121+
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
122+
p = Promise.resolve(resolver(root, args, context, info))
123+
124+
def resolve_connection(resolved):
125+
if isinstance(resolved, connection_type):
126+
return resolved
127+
128+
assert isinstance(resolved, Iterable), (
129+
'Resolved value from the connection field have to be iterable or instance of {}. '
130+
'Received "{}"'
131+
).format(connection_type, resolved)
132+
connection = connection_from_list(
133+
resolved,
134+
args,
135+
connection_type=connection_type,
136+
edge_type=connection_type.Edge,
137+
pageinfo_type=PageInfo
138+
)
139+
connection.iterable = resolved
140+
return connection
141+
142+
return p.then(resolve_connection)
140143

141144
def get_resolver(self, parent_resolver):
142145
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)

0 commit comments

Comments
 (0)