Ejemplo n.º 1
0
 protected function resolveList(FieldInterface $field, AstFieldInterface $ast, $parentValue)
 {
     /** @var AstQuery $ast */
     $resolvedValue = $this->doResolve($field, $ast, $parentValue);
     $this->resolveValidator->assertValidResolvedValueForField($field, $resolvedValue);
     if (null === $resolvedValue) {
         return null;
     }
     /** @var AbstractListType $type */
     $type = $field->getType()->getNullableType();
     $itemType = $type->getNamedType();
     $fakeAst = clone $ast;
     if ($fakeAst instanceof AstQuery) {
         $fakeAst->setArguments([]);
     }
     $fakeField = new Field(['name' => $field->getName(), 'type' => $itemType]);
     $result = [];
     foreach ($resolvedValue as $resolvedValueItem) {
         try {
             $fakeField->getConfig()->set('resolve', function () use($resolvedValueItem) {
                 return $resolvedValueItem;
             });
             switch ($itemType->getNullableType()->getKind()) {
                 case TypeMap::KIND_ENUM:
                 case TypeMap::KIND_SCALAR:
                     $value = $this->resolveScalar($fakeField, $fakeAst, $resolvedValueItem);
                     break;
                 case TypeMap::KIND_OBJECT:
                     $value = $this->resolveObject($fakeField, $fakeAst, $resolvedValueItem);
                     break;
                 case TypeMap::KIND_UNION:
                 case TypeMap::KIND_INTERFACE:
                     $value = $this->resolveComposite($fakeField, $fakeAst, $resolvedValueItem);
                     break;
                 default:
                     $value = null;
             }
         } catch (\Exception $e) {
             $this->executionContext->addError($e);
             $value = null;
         }
         $result[] = $value;
     }
     return $result;
 }