@@ -10,11 +10,13 @@ def connection_from_list(data, args=None, **kwargs):
10
10
a connection object for use in GraphQL. It uses array offsets as pagination,
11
11
so pagination will only work if the array is static.
12
12
'''
13
+ _len = len (data )
13
14
return connection_from_list_slice (
14
15
data ,
15
16
args ,
16
17
slice_start = 0 ,
17
- list_length = len (data ),
18
+ list_length = _len ,
19
+ list_slice_length = _len ,
18
20
** kwargs
19
21
)
20
22
@@ -29,7 +31,7 @@ def connection_from_promised_list(data_promise, args=None, **kwargs):
29
31
30
32
def connection_from_list_slice (list_slice , args = None , connection_type = None ,
31
33
edge_type = None , pageinfo_type = None ,
32
- slice_start = 0 , list_length = 0 ):
34
+ slice_start = 0 , list_length = 0 , list_slice_length = None ):
33
35
'''
34
36
Given a slice (subset) of an array, returns a connection object for use in
35
37
GraphQL.
@@ -48,7 +50,8 @@ def connection_from_list_slice(list_slice, args=None, connection_type=None,
48
50
after = args .get ('after' )
49
51
first = args .get ('first' )
50
52
last = args .get ('last' )
51
- list_slice_length = len (list_slice )
53
+ if list_slice_length is None :
54
+ list_slice_length = len (list_slice )
52
55
slice_end = slice_start + list_slice_length
53
56
before_offset = get_offset_with_default (before , list_length )
54
57
after_offset = get_offset_with_default (after , - 1 )
0 commit comments