mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-30 05:23:57 +03:00
Improved Promise connection abstraction
This commit is contained in:
parent
16e9f221b5
commit
760ccc8358
|
@ -119,10 +119,7 @@ class IterableConnectionField(Field):
|
||||||
return connection_type
|
return connection_type
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
|
def resolve_connection(cls, connection_type, args, resolved):
|
||||||
p = Promise.resolve(resolver(root, args, context, info))
|
|
||||||
|
|
||||||
def resolve_connection(resolved):
|
|
||||||
if isinstance(resolved, connection_type):
|
if isinstance(resolved, connection_type):
|
||||||
return resolved
|
return resolved
|
||||||
|
|
||||||
|
@ -140,7 +137,15 @@ class IterableConnectionField(Field):
|
||||||
connection.iterable = resolved
|
connection.iterable = resolved
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
return p.then(resolve_connection)
|
@classmethod
|
||||||
|
def connection_resolver(cls, resolver, connection_type, root, args, context, info):
|
||||||
|
resolved = resolver(root, args, context, info)
|
||||||
|
|
||||||
|
on_resolve = partial(cls.resolve_connection, connection_type, args)
|
||||||
|
if isinstance(resolved, Promise):
|
||||||
|
return resolved.then(on_resolve)
|
||||||
|
|
||||||
|
return on_resolve(resolved)
|
||||||
|
|
||||||
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