Skip to content

Commit 6982111

Browse files
authored
Merge pull request #65 from nuwave/fix/connection-cursor
fix start and end cursors for connection edges
2 parents 2ac5f8b + e6bc8ea commit 6982111

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/Support/Definition/PageInfoType.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function fields()
5454
if ($collection instanceof LengthAwarePaginator) {
5555
return $this->encodeGlobalId(
5656
'arrayconnection',
57-
$collection->firstItem() * $collection->currentPage()
57+
$collection->currentPage()
5858
);
5959
}
6060

@@ -66,10 +66,11 @@ public function fields()
6666
'description' => 'When paginating forwards, the cursor to continue.',
6767
'resolve' => function ($collection) {
6868
if ($collection instanceof LengthAwarePaginator) {
69-
return $this->encodeGlobalId(
70-
'arrayconnection',
71-
$collection->lastItem() * $collection->currentPage()
72-
);
69+
$cursor = $collection->hasMorePages()
70+
? $collection->lastItem()
71+
: $collection->currentPage();
72+
73+
return $this->encodeGlobalId('arrayconnection', $cursor);
7374
}
7475
},
7576
],

0 commit comments

Comments
 (0)