Youshido\GraphQL\Execution\Processor::resolveField PHP Method

resolveField() protected method

protected resolveField ( Youshido\GraphQL\Field\FieldInterface $field, Youshido\GraphQL\Parser\Ast\Interfaces\FieldInterface $ast, $parentValue = null, $fromObject = false )
$field Youshido\GraphQL\Field\FieldInterface
$ast Youshido\GraphQL\Parser\Ast\Interfaces\FieldInterface
    protected function resolveField(FieldInterface $field, AstFieldInterface $ast, $parentValue = null, $fromObject = false)
    {
        try {
            /** @var AbstractObjectType $type */
            $type = $field->getType();
            $nonNullType = $type->getNullableType();
            if (self::TYPE_NAME_QUERY == $ast->getName()) {
                return $nonNullType->getName();
            }
            $this->resolveValidator->assetTypeHasField($nonNullType, $ast);
            $targetField = $nonNullType->getField($ast->getName());
            $this->prepareAstArguments($targetField, $ast, $this->executionContext->getRequest());
            $this->resolveValidator->assertValidArguments($targetField, $ast, $this->executionContext->getRequest());
            switch ($kind = $targetField->getType()->getNullableType()->getKind()) {
                case TypeMap::KIND_ENUM:
                case TypeMap::KIND_SCALAR:
                    if ($ast instanceof AstQuery && $ast->hasFields()) {
                        throw new ResolveException(sprintf('You can\'t specify fields for scalar type "%s"', $targetField->getType()->getNullableType()->getName()), $ast->getLocation());
                    }
                    return $this->resolveScalar($targetField, $ast, $parentValue);
                case TypeMap::KIND_OBJECT:
                    /** @var $type AbstractObjectType */
                    if (!$ast instanceof AstQuery) {
                        throw new ResolveException(sprintf('You have to specify fields for "%s"', $ast->getName()), $ast->getLocation());
                    }
                    return $this->resolveObject($targetField, $ast, $parentValue);
                case TypeMap::KIND_LIST:
                    return $this->resolveList($targetField, $ast, $parentValue);
                case TypeMap::KIND_UNION:
                case TypeMap::KIND_INTERFACE:
                    if (!$ast instanceof AstQuery) {
                        throw new ResolveException(sprintf('You have to specify fields for "%s"', $ast->getName()), $ast->getLocation());
                    }
                    return $this->resolveComposite($targetField, $ast, $parentValue);
                default:
                    throw new ResolveException(sprintf('Resolving type with kind "%s" not supported', $kind));
            }
        } catch (\Exception $e) {
            $this->executionContext->addError($e);
            if ($fromObject) {
                throw $e;
            }
            return null;
        }
    }