public function assertValidResolvedValueForField(FieldInterface $field, $resolvedValue) { if ($field->getType()->getKind() == TypeMap::KIND_NON_NULL && is_null($resolvedValue)) { throw new ResolveException(sprintf('Cannot return null for non-nullable field "%s"', $field->getName())); } if (!$field->getType()->getNullableType()->isValidValue($resolvedValue)) { throw new ResolveException(sprintf('Not valid resolved type for field "%s"', $field->getName())); } }
/** * @return AbstractType */ public function getReturnType() { return $this->field->getType(); }
public function resolveType(FieldInterface $value) { return $value->getType(); }
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; } }