Skip to content

Commit 5dc5b7c

Browse files
authored
Merge pull request #778 from rsolyanik/fix_totalcount_promise
Made it possible for totalCount to be a promise
2 parents d7c2e25 + e13f43b commit 5dc5b7c

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/Relay/Connection/ConnectionInterface.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
namespace Overblog\GraphQLBundle\Relay\Connection;
66

7+
use GraphQL\Executor\Promise\Promise;
8+
79
interface ConnectionInterface
810
{
911
/**
@@ -33,14 +35,16 @@ public function getPageInfo(): ?PageInfoInterface;
3335
public function setPageInfo(PageInfoInterface $pageInfo): void;
3436

3537
/**
36-
* Get the total count.
38+
* Get the total count or promise that returns the total count.
3739
*
38-
* @return int
40+
* @return int|Promise|null
3941
*/
40-
public function getTotalCount(): ?int;
42+
public function getTotalCount();
4143

4244
/**
43-
* Set the total count.
45+
* Set the total count or promise that returns the total count.
46+
*
47+
* @param int|Promise $totalCount
4448
*/
45-
public function setTotalCount(int $totalCount): void;
49+
public function setTotalCount($totalCount): void;
4650
}

src/Relay/Connection/Output/Connection.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Overblog\GraphQLBundle\Relay\Connection\Output;
66

7+
use GraphQL\Executor\Promise\Promise;
78
use Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface;
89
use Overblog\GraphQLBundle\Relay\Connection\EdgeInterface;
910
use Overblog\GraphQLBundle\Relay\Connection\PageInfoInterface;
@@ -16,7 +17,9 @@ class Connection implements ConnectionInterface
1617
protected array $edges;
1718

1819
protected ?PageInfoInterface $pageInfo;
19-
protected ?int $totalCount = null;
20+
21+
/** @var int|Promise|null Total count or promise that returns the total count */
22+
protected $totalCount = null;
2023

2124
public function __construct(array $edges = [], PageInfoInterface $pageInfo = null)
2225
{
@@ -59,15 +62,15 @@ public function setPageInfo(PageInfoInterface $pageInfo): void
5962
/**
6063
* {@inheritdoc}
6164
*/
62-
public function getTotalCount(): ?int
65+
public function getTotalCount()
6366
{
6467
return $this->totalCount;
6568
}
6669

6770
/**
6871
* {@inheritdoc}
6972
*/
70-
public function setTotalCount(int $totalCount): void
73+
public function setTotalCount($totalCount): void
7174
{
7275
$this->totalCount = $totalCount;
7376
}

0 commit comments

Comments
 (0)