Skip to content

Commit 095e7dc

Browse files
committed
fixed PageInfo to expected behavior
1 parent d656040 commit 095e7dc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

src/Relay/Connection/ConnectionBuilder.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,10 @@ public function connectionFromArraySlice(array $arraySlice, $args, array $meta):
129129
$beforeOffset = $this->getOffsetWithDefault($before, $arrayLength);
130130
$afterOffset = $this->getOffsetWithDefault($after, -1);
131131

132+
if ($afterOffset > $beforeOffset) {
133+
throw new InvalidArgumentException('Arguments "before" and "after" cannot be intersected');
134+
}
135+
132136
$startOffset = max($sliceStart - 1, $afterOffset, -1) + 1;
133137
$endOffset = min($sliceEnd, $beforeOffset, $arrayLength);
134138

@@ -161,14 +165,12 @@ public function connectionFromArraySlice(array $arraySlice, $args, array $meta):
161165

162166
$firstEdge = $edges[0] ?? null;
163167
$lastEdge = end($edges);
164-
$lowerBound = $after ? ($afterOffset + 1) : 0;
165-
$upperBound = $before ? $beforeOffset : $arrayLength;
166168

167169
$pageInfo = new PageInfo(
168170
$firstEdge instanceof EdgeInterface ? $firstEdge->getCursor() : null,
169171
$lastEdge instanceof EdgeInterface ? $lastEdge->getCursor() : null,
170-
null !== $last ? $startOffset > $lowerBound : false,
171-
null !== $first ? $endOffset < $upperBound : false
172+
$startOffset > 0,
173+
$endOffset < $arrayLength
172174
);
173175

174176
return $this->createConnection($edges, $pageInfo);

0 commit comments

Comments
 (0)