Skip to content

Commit 8919ca2

Browse files
committed
use instance name in connection registrar
1 parent ca8fa99 commit 8919ca2

File tree

1 file changed

+24
-8
lines changed

1 file changed

+24
-8
lines changed

src/Schema/Registrars/ConnectionRegistrar.php

+24-8
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,14 @@ public function register($name, $field)
5151
*/
5252
public function instance($name, $parent = null, $fresh = false)
5353
{
54-
$typeName = $this->getName($name);
54+
$instanceName = $this->instanceName($name);
55+
$typeName = $this->typeName($name);
5556

56-
if (! $fresh && $this->instances->has($typeName)) {
57-
return $this->instances->get($typeName);
57+
if (! $fresh && $this->instances->has($instanceName)) {
58+
return $this->instances->get($instanceName);
5859
}
5960

60-
$key = $parent ? $parent.'.'.$typeName : $typeName;
61+
$key = $parent ? $parent.'.'.$instanceName : $instanceName;
6162
$nodeType = $this->getSchema()->typeInstance($typeName);
6263
$instance = $this->getInstance($name, $nodeType);
6364

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

8485
$pageInfoType = $this->getSchema()->typeInstance('pageInfo');
85-
$edgeType = $this->getSchema()->edgeInstance($typeName, $nodeType);
86+
$edgeType = $this->getSchema()->edgeInstance($instanceName, $nodeType);
8687

8788
$connection->setEdgeType($edgeType);
8889
$connection->setPageInfoType($pageInfoType);
@@ -107,7 +108,22 @@ public function getInstance($name, ObjectType $nodeType)
107108
* @param mixed $name
108109
* @return string
109110
*/
110-
protected function getName($name)
111+
protected function instanceName($name)
112+
{
113+
if ($name instanceof Connection) {
114+
return strtolower(get_class($name));
115+
}
116+
117+
return $name;
118+
}
119+
120+
/**
121+
* Extract name.
122+
*
123+
* @param mixed $name
124+
* @return string
125+
*/
126+
protected function typeName($name)
111127
{
112128
if ($name instanceof Connection) {
113129
return $name->type();

0 commit comments

Comments
 (0)