|
5 | 5 | import six
|
6 | 6 |
|
7 | 7 | from graphql_relay import connection_from_list
|
| 8 | +from promise import Promise |
8 | 9 |
|
9 | 10 | from ..types import (AbstractType, Boolean, Enum, Int, Interface, List, NonNull, Scalar, String,
|
10 | 11 | Union)
|
@@ -118,26 +119,34 @@ def type(self):
|
118 | 119 | return connection_type
|
119 | 120 |
|
120 | 121 | @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): |
125 | 124 | return resolved
|
126 | 125 |
|
127 | 126 | assert isinstance(resolved, Iterable), (
|
128 | 127 | 'Resolved value from the connection field have to be iterable or instance of {}. '
|
129 | 128 | 'Received "{}"'
|
130 |
| - ).format(connection, resolved) |
| 129 | + ).format(connection_type, resolved) |
131 | 130 | connection = connection_from_list(
|
132 | 131 | resolved,
|
133 | 132 | args,
|
134 |
| - connection_type=connection, |
135 |
| - edge_type=connection.Edge, |
| 133 | + connection_type=connection_type, |
| 134 | + edge_type=connection_type.Edge, |
136 | 135 | pageinfo_type=PageInfo
|
137 | 136 | )
|
138 | 137 | connection.iterable = resolved
|
139 | 138 | return connection
|
140 | 139 |
|
| 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 | + |
141 | 150 | def get_resolver(self, parent_resolver):
|
142 | 151 | resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
|
143 | 152 | return partial(self.connection_resolver, resolver, self.type)
|
|
0 commit comments