mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-27 03:53:56 +03:00
Add support to return a promise for connections.
This commit is contained in:
parent
0a80119f5e
commit
ea69be6117
|
@ -118,25 +118,28 @@ class IterableConnectionField(Field):
|
||||||
return connection_type
|
return connection_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def connection_resolver(cls, resolver, connection, root, args, context, info):
|
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
|
||||||
resolved = resolver(root, args, context, info)
|
p = Promise.resolve(resolver(root, args, context, info))
|
||||||
|
|
||||||
if isinstance(resolved, connection):
|
def resolve_connection(resolved):
|
||||||
return resolved
|
if isinstance(resolved, connection_type):
|
||||||
|
return resolved
|
||||||
|
|
||||||
assert isinstance(resolved, Iterable), (
|
assert isinstance(resolved, Iterable), (
|
||||||
'Resolved value from the connection field have to be iterable or instance of {}. '
|
'Resolved value from the connection field have to be iterable or instance of {}. '
|
||||||
'Received "{}"'
|
'Received "{}"'
|
||||||
).format(connection, resolved)
|
).format(connection_type, resolved)
|
||||||
connection = connection_from_list(
|
connection = connection_from_list(
|
||||||
resolved,
|
resolved,
|
||||||
args,
|
args,
|
||||||
connection_type=connection,
|
connection_type=connection_type,
|
||||||
edge_type=connection.Edge,
|
edge_type=connection_type.Edge,
|
||||||
pageinfo_type=PageInfo
|
pageinfo_type=PageInfo
|
||||||
)
|
)
|
||||||
connection.iterable = resolved
|
connection.iterable = resolved
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
return p.then(resolve_connection)
|
||||||
|
|
||||||
def get_resolver(self, parent_resolver):
|
def get_resolver(self, parent_resolver):
|
||||||
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
|
resolver = super(IterableConnectionField, self).get_resolver(parent_resolver)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user