GraphQL\Executor\Executor::completeValue PHP Method

completeValue() private static method

If the field type is Non-Null, then this recursively completes the value for the inner type. It throws a field error if that completion returns null, as per the "Nullability" section of the spec. If the field type is a List, then this recursively completes the value for the inner type on each item in the list. If the field type is a Scalar or Enum, ensures the completed value is a legal value of the type by calling the serialize method of GraphQL type definition. If the field is an abstract type, determine the runtime type of the value and then complete based on that type Otherwise, the field type expects a sub-selection set, and will complete the value by evaluating all sub-selections.
private static completeValue ( ExecutionContext $exeContext, Type $returnType, FieldNode[] $fieldNodes, ResolveInfo $info, array $path, &$result ) : array | null | GraphQL\Executor\Promise\Promise
$exeContext ExecutionContext
$returnType GraphQL\Type\Definition\Type
$fieldNodes GraphQL\Language\AST\FieldNode[]
$info GraphQL\Type\Definition\ResolveInfo
$path array
$result
return array | null | GraphQL\Executor\Promise\Promise
    private static function completeValue(ExecutionContext $exeContext, Type $returnType, $fieldNodes, ResolveInfo $info, $path, &$result)
    {
        // If result is a Promise, apply-lift over completeValue.
        if (self::$promiseAdapter->isPromise($result)) {
            return $result->then(function (&$resolved) use($exeContext, $returnType, $fieldNodes, $info, $path) {
                return self::completeValue($exeContext, $returnType, $fieldNodes, $info, $path, $resolved);
            });
        }
        if ($result instanceof \Exception) {
            throw $result;
        }
        // If field type is NonNull, complete for inner type, and throw field error
        // if result is null.
        if ($returnType instanceof NonNull) {
            $completed = self::completeValue($exeContext, $returnType->getWrappedType(), $fieldNodes, $info, $path, $result);
            if ($completed === null) {
                throw new InvariantViolation('Cannot return null for non-nullable field ' . $info->parentType . '.' . $info->fieldName . '.');
            }
            return $completed;
        }
        // If result is null-like, return null.
        if (null === $result) {
            return null;
        }
        // If field type is List, complete each item in the list with the inner type
        if ($returnType instanceof ListOfType) {
            return self::completeListValue($exeContext, $returnType, $fieldNodes, $info, $path, $result);
        }
        // If field type is Scalar or Enum, serialize to a valid value, returning
        // null if serialization is not possible.
        if ($returnType instanceof LeafType) {
            return self::completeLeafValue($returnType, $result);
        }
        if ($returnType instanceof AbstractType) {
            return self::completeAbstractValue($exeContext, $returnType, $fieldNodes, $info, $path, $result);
        }
        // Field type must be Object, Interface or Union and expect sub-selections.
        if ($returnType instanceof ObjectType) {
            return self::completeObjectValue($exeContext, $returnType, $fieldNodes, $info, $path, $result);
        }
        throw new \RuntimeException("Cannot complete value of unexpected type \"{$returnType}\".");
    }