Skip to content

Commit

Permalink
added additional fields to pageInfo type
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Jun 30, 2016
1 parent ab9dac5 commit a44fdc7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
35 changes: 34 additions & 1 deletion src/Support/Definition/PageInfoType.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,40 @@ public function fields()

return null;
}
]
],
'total' => [
'type' => Type::int(),
'description' => 'Total number of node in connection.',
'resolve' => function ($collection) {
if ($collection instanceof LengthAwarePaginator) {
return $collection->total();
}

return null;
}
],
'count' => [
'type' => Type::int(),
'description' => 'Count of nodes in current request.',
'resolve' => function ($collection) {
if ($collection instanceof LengthAwarePaginator) {
return $collection->count();
}

return null;
}
],
'currentPage' => [
'type' => Type::int(),
'description' => 'Current page of request.',
'resolve' => function ($collection) {
if ($collection instanceof LengthAwarePaginator) {
return $collection->currentPage();
}

return null;
}
],
];
}
}
14 changes: 14 additions & 0 deletions tests/Queries/PaginationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertCount(2, $edges);
$this->assertEquals($this->tasks->get(0)->title, array_get($edges, '0.node.title'));
$this->assertEquals($this->tasks->get(1)->title, array_get($edges, '1.node.title'));
$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->assertNotNull(array_get($edges, '1.cursor'));

$after = array_get($edges, '1.cursor');
Expand All @@ -72,6 +75,9 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertCount(2, $edges);
$this->assertEquals($this->tasks->get(2)->title, array_get($edges, '0.node.title'));
$this->assertEquals($this->tasks->get(3)->title, array_get($edges, '1.node.title'));
$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'));

$after = array_get($edges, '1.cursor');
$query = $this->getQuery($id, $first, $after);
Expand All @@ -81,6 +87,9 @@ public function itCanPaginateConnectionWithLengthAwarePaginator()
$this->assertCount(2, $edges);
$this->assertEquals($this->tasks->get(4)->title, array_get($edges, '0.node.title'));
$this->assertEquals($this->tasks->get(5)->title, array_get($edges, '1.node.title'));
$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'));
}

/**
Expand Down Expand Up @@ -142,6 +151,11 @@ protected function getQuery($id, $first, $after = null)
node(id:"'.$id.'") {
... on User {
tasks('.$args.') {
pageInfo {
total
count
currentPage
}
edges {
cursor
node {
Expand Down

0 comments on commit a44fdc7

Please sign in to comment.