Skip to content

Commit

Permalink
added last page to page info
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Jun 30, 2016
1 parent ebe056a commit 902b98f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Support/Definition/PageInfoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ public function fields()
return $collection->currentPage();
}

return null;
}
],
'lastPage' => [
'type' => Type::int(),
'description' => 'Last page in connection.',
'resolve' => function ($collection) {
if ($collection instanceof LengthAwarePaginator) {
return $collection->lastPage();
}

return null;
}
],
Expand Down
4 changes: 4 additions & 0 deletions tests/Queries/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertEquals(6, array_get($data, 'data.node.tasks.pageInfo.total'));
$this->assertEquals(2, array_get($data, 'data.node.tasks.pageInfo.count'));
$this->assertEquals(1, array_get($data, 'data.node.tasks.pageInfo.currentPage'));
$this->assertEquals(3, array_get($data, 'data.node.tasks.pageInfo.lastPage'));
$this->assertNotNull(array_get($edges, '1.cursor'));

$after = array_get($edges, '1.cursor');
Expand All @@ -78,6 +79,7 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertEquals(6, array_get($data, 'data.node.tasks.pageInfo.total'));
$this->assertEquals(2, array_get($data, 'data.node.tasks.pageInfo.count'));
$this->assertEquals(2, array_get($data, 'data.node.tasks.pageInfo.currentPage'));
$this->assertEquals(3, array_get($data, 'data.node.tasks.pageInfo.lastPage'));

$after = array_get($edges, '1.cursor');
$query = $this->getQuery($id, $first, $after);
Expand All @@ -90,6 +92,7 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertEquals(6, array_get($data, 'data.node.tasks.pageInfo.total'));
$this->assertEquals(2, array_get($data, 'data.node.tasks.pageInfo.count'));
$this->assertEquals(3, array_get($data, 'data.node.tasks.pageInfo.currentPage'));
$this->assertEquals(3, array_get($data, 'data.node.tasks.pageInfo.lastPage'));
}

/**
Expand Down Expand Up @@ -155,6 +158,7 @@ protected function getQuery($id, $first, $after = null)
total
count
currentPage
lastPage
}
edges {
cursor
Expand Down

0 comments on commit 902b98f

Please sign in to comment.