From 8919ca2f26df687bfe1f04fc50da975f9809611d Mon Sep 17 00:00:00 2001 From: Christopher Moore Date: Sat, 27 Aug 2016 10:53:27 -0700 Subject: [PATCH] use instance name in connection registrar --- src/Schema/Registrars/ConnectionRegistrar.php | 32 ++++++++++++++----- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Schema/Registrars/ConnectionRegistrar.php b/src/Schema/Registrars/ConnectionRegistrar.php index b9a245e497..6513954d26 100644 --- a/src/Schema/Registrars/ConnectionRegistrar.php +++ b/src/Schema/Registrars/ConnectionRegistrar.php @@ -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); @@ -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); @@ -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();