Skip to content

Commit

Permalink
fix in type collector
Browse files Browse the repository at this point in the history
  • Loading branch information
portey committed Mar 9, 2016
1 parent 71505b3 commit b1f2d3c
Showing 1 changed file with 29 additions and 12 deletions.
41 changes: 29 additions & 12 deletions src/Introspection/Traits/TypeCollectorTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait TypeCollectorTrait
*/
protected function collectTypes($type)
{
if(!$type) {
if (!$type) {
return;
}

Expand All @@ -32,6 +32,17 @@ protected function collectTypes($type)
case TypeMap::KIND_ENUM:
case TypeMap::KIND_SCALAR:
$this->insertType($type->getName(), $type);

if ($type->getKind() == TypeMap::KIND_UNION) {
foreach ($type->getTypes() as $subType) {
if ($this->insertType($subType->getName(), $subType)) {
$this->collectFieldsArgsTypes($subType);

$this->checkAndInsertInterfaces($subType);
}
}
}

break;

case TypeMap::KIND_INPUT_OBJECT:
Expand All @@ -40,20 +51,12 @@ protected function collectTypes($type)
$outputType = $type->getConfig()->getOutputType();

if ($outputType) {
if($this->insertType($outputType->getName(), $outputType)) {
if ($this->insertType($outputType->getName(), $outputType)) {
$this->collectFieldsArgsTypes($outputType);
}
}
} else {
$interfaces = $type->getConfig()->getInterfaces();

if(is_array($interfaces) && $interfaces) {
foreach($interfaces as $interface){
if($this->insertType($interface->getName(), $interface)){
$this->collectFieldsArgsTypes($interface);
}
}
}
$this->checkAndInsertInterfaces($type);
}

if ($this->insertType($type->getName(), $type)) {
Expand All @@ -65,6 +68,7 @@ protected function collectTypes($type)
$subItem = $type->getConfig()->getItem();
if ($this->insertType($subItem->getName(), $subItem)) {
$this->collectFieldsArgsTypes($subItem);
$this->collectTypes($subItem);
}

foreach ($type->getConfig()->getArguments() as $argument) {
Expand All @@ -75,14 +79,27 @@ protected function collectTypes($type)
}
}

private function checkAndInsertInterfaces($type)
{
$interfaces = $type->getConfig()->getInterfaces();

if (is_array($interfaces) && $interfaces) {
foreach ($interfaces as $interface) {
if ($this->insertType($interface->getName(), $interface)) {
$this->collectFieldsArgsTypes($interface);
}
}
}
}

/**
* @param $type TypeInterface
*/
private function collectFieldsArgsTypes($type)
{
foreach ($type->getConfig()->getFields() as $field) {
/** @var FieldConfig $field */
if($field->getType() instanceof AbstractMutationType) {
if ($field->getType() instanceof AbstractMutationType) {
$this->collectTypes($field->getType()->getOutputType());
}

Expand Down

0 comments on commit b1f2d3c

Please sign in to comment.