@@ -31,7 +31,7 @@ def connection_from_promised_list(data_promise, args=None, **kwargs):
31
31
32
32
def connection_from_list_slice (list_slice , args = None , connection_type = None ,
33
33
edge_type = None , pageinfo_type = None ,
34
- slice_start = 0 , list_length = 0 , list_slice_length = None ):
34
+ slice_start = 0 , list_length = 0 , list_slice_length = None , limit = None ):
35
35
'''
36
36
Given a slice (subset) of an array, returns a connection object for use in
37
37
GraphQL.
@@ -77,11 +77,13 @@ def connection_from_list_slice(list_slice, args=None, connection_type=None,
77
77
end_offset - last
78
78
)
79
79
80
+ _start = max (start_offset - slice_start , 0 )
81
+ _finish = list_slice_length - (slice_end - end_offset )
82
+ if limit and _finish - _start > limit :
83
+ _finish = _start + limit
84
+
80
85
# If supplied slice is too large, trim it down before mapping over it.
81
- _slice = list_slice [
82
- max (start_offset - slice_start , 0 ):
83
- list_slice_length - (slice_end - end_offset )
84
- ]
86
+ _slice = list_slice [_start :_finish ]
85
87
edges = [
86
88
edge_type (
87
89
node = node ,
@@ -93,16 +95,14 @@ def connection_from_list_slice(list_slice, args=None, connection_type=None,
93
95
94
96
first_edge_cursor = edges [0 ].cursor if edges else None
95
97
last_edge_cursor = edges [- 1 ].cursor if edges else None
96
- lower_bound = after_offset + 1 if after else 0
97
- upper_bound = before_offset if before else list_length
98
98
99
99
return connection_type (
100
100
edges = edges ,
101
101
page_info = pageinfo_type (
102
102
start_cursor = first_edge_cursor ,
103
103
end_cursor = last_edge_cursor ,
104
- has_previous_page = isinstance ( last , int ) and start_offset > lower_bound ,
105
- has_next_page = isinstance ( first , int ) and end_offset < upper_bound
104
+ has_previous_page = _start > 0 ,
105
+ has_next_page = _finish < list_slice_length
106
106
)
107
107
)
108
108
0 commit comments