Skip to content

Commit

Permalink
BUGFIX: Ensure referential equality of two connection types in new Gr…
Browse files Browse the repository at this point in the history
…aphQL 4 compatible node/edges implementation
  • Loading branch information
Aaron Carlino committed May 7, 2021
1 parent 636c212 commit 45c56bd
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions src/Pagination/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Connection implements OperationResolver
*/
protected $connectedType;

/**
* Cache the instance of the connection type to guarantee referential equality for graphql-php
* @var ObjectType
*/
protected $connectionTypeInstance;

/**
* @var string
*/
Expand Down Expand Up @@ -122,13 +128,21 @@ public function setConnectionType($type)
* Evaluate Connection type
*
* @param bool $evaluate
* @param bool $useCache When true, rely on the previous instance created
* @return ObjectType|Callable
*/
public function getConnectionType($evaluate = true)
public function getConnectionType($evaluate = true, $useCache = true)
{
return ($evaluate && is_callable($this->connectedType))
if ($useCache && $this->connectionTypeInstance) {
return $this->connectionTypeInstance;
}
$instance = ($evaluate && is_callable($this->connectedType))
? call_user_func($this->connectedType)
: $this->connectedType;

$this->connectionTypeInstance = $instance;

return $this->connectionTypeInstance;
}

/**
Expand Down

0 comments on commit 45c56bd

Please sign in to comment.