Skip to content

Commit

Permalink
use instance name in connection registrar
Browse files Browse the repository at this point in the history
  • Loading branch information
chrissm79 committed Aug 27, 2016
1 parent ca8fa99 commit 8919ca2
Showing 1 changed file with 24 additions and 8 deletions.
32 changes: 24 additions & 8 deletions src/Schema/Registrars/ConnectionRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,14 @@ public function register($name, $field)
*/
public function instance($name, $parent = null, $fresh = false)
{
$typeName = $this->getName($name);
$instanceName = $this->instanceName($name);
$typeName = $this->typeName($name);

if (! $fresh && $this->instances->has($typeName)) {
return $this->instances->get($typeName);
if (! $fresh && $this->instances->has($instanceName)) {
return $this->instances->get($instanceName);
}

$key = $parent ? $parent.'.'.$typeName : $typeName;
$key = $parent ? $parent.'.'.$instanceName : $instanceName;
$nodeType = $this->getSchema()->typeInstance($typeName);
$instance = $this->getInstance($name, $nodeType);

Expand All @@ -77,12 +78,12 @@ public function getInstance($name, ObjectType $nodeType)
{
$isConnection = $name instanceof Connection;
$connection = new RelayConnectionType();
$typeName = $this->getName($name);
$connectionName = (!preg_match('/Connection$/', $typeName)) ? $typeName.'Connection' : $typeName;
$instanceName = $this->instanceName($name);
$connectionName = (!preg_match('/Connection$/', $instanceName)) ? $instanceName.'Connection' : $instanceName;
$connection->setName(studly_case($connectionName));

$pageInfoType = $this->getSchema()->typeInstance('pageInfo');
$edgeType = $this->getSchema()->edgeInstance($typeName, $nodeType);
$edgeType = $this->getSchema()->edgeInstance($instanceName, $nodeType);

$connection->setEdgeType($edgeType);
$connection->setPageInfoType($pageInfoType);
Expand All @@ -107,7 +108,22 @@ public function getInstance($name, ObjectType $nodeType)
* @param mixed $name
* @return string
*/
protected function getName($name)
protected function instanceName($name)
{
if ($name instanceof Connection) {
return strtolower(get_class($name));
}

return $name;
}

/**
* Extract name.
*
* @param mixed $name
* @return string
*/
protected function typeName($name)
{
if ($name instanceof Connection) {
return $name->type();
Expand Down

0 comments on commit 8919ca2

Please sign in to comment.