Skip to content

Commit 3ba3aa2

Browse files
committed
array_connection: return all elements if cursors are on the outside
Replicates graphql/graphql-relay-js@fa978fb
1 parent ac97cce commit 3ba3aa2

File tree

2 files changed

+58
-166
lines changed

2 files changed

+58
-166
lines changed

src/graphql_relay/connection/array_connection.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,17 @@ def connection_from_array_slice(
135135
slice_end = slice_start + array_slice_length
136136
if array_length is None:
137137
array_length = slice_end
138-
before_offset = get_offset_with_default(before, array_length)
138+
139+
start_offset = max(slice_start, 0)
140+
end_offset = min(slice_end, array_length)
141+
139142
after_offset = get_offset_with_default(after, -1)
143+
if 0 <= after_offset < array_length:
144+
start_offset = max(start_offset, after_offset + 1)
140145

141-
start_offset = max(slice_start - 1, after_offset, -1) + 1
142-
end_offset = min(slice_end, before_offset, array_length)
146+
before_offset = get_offset_with_default(before, end_offset)
147+
if 0 <= before_offset < array_length:
148+
end_offset = min(end_offset, before_offset)
143149

144150
if isinstance(first, int):
145151
if first < 0:
@@ -153,9 +159,7 @@ def connection_from_array_slice(
153159
start_offset = max(start_offset, end_offset - last)
154160

155161
# If supplied slice is too large, trim it down before mapping over it.
156-
trimmed_slice = array_slice[
157-
start_offset - slice_start : array_slice_length - (slice_end - end_offset)
158-
]
162+
trimmed_slice = array_slice[start_offset - slice_start : end_offset - slice_start]
159163

160164
edges = [
161165
edge_type(node=value, cursor=offset_to_cursor(start_offset + index))

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy