mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-24 15:47:23 +03:00
Add connection_from_list_slice support to Connection
This allows to return e.g. `Connection.for_node(Node).from_list([1, 2, 3, 4], args, context, info, 5389)` to get pagination support for sliced lists.
This commit is contained in:
parent
1711e6a529
commit
c6f8c30c84
|
@ -87,12 +87,17 @@ class Connection(ObjectType):
|
||||||
{'edge_type': edge_type, 'edges': edges})
|
{'edge_type': edge_type, 'edges': edges})
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def from_list(cls, iterable, args, context, info):
|
def from_list(cls, iterable, args, context, info, total_count=None):
|
||||||
assert isinstance(
|
assert isinstance(
|
||||||
iterable, Iterable), 'Resolved value from the connection field have to be iterable'
|
iterable, Iterable), 'Resolved value from the connection field have to be iterable'
|
||||||
connection = connection_from_list(
|
|
||||||
|
list_slice_length = len(iterable)
|
||||||
|
list_length = total_count if total_count else list_slice_length
|
||||||
|
|
||||||
|
connection = connection_from_list_slice(
|
||||||
iterable, args, connection_type=cls,
|
iterable, args, connection_type=cls,
|
||||||
edge_type=cls.edge_type, pageinfo_type=PageInfo)
|
edge_type=cls.edge_type, pageinfo_type=PageInfo,
|
||||||
|
list_length=list_length, list_slice_length=list_slice_length)
|
||||||
connection.set_connection_data(iterable)
|
connection.set_connection_data(iterable)
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user