You are here

protected function FieldPluginBase::unwrapResult in GraphQL 8.3

Unwrap the resolved values.

Parameters

array $result: The resolved values.

\GraphQL\Type\Definition\ResolveInfo $info: The resolve info object.

Return value

mixed The extracted values (an array of values in case this is a list, an arbitrary value if it isn't).

1 call to FieldPluginBase::unwrapResult()
FieldPluginBase::resolveDeferred in src/Plugin/GraphQL/Fields/FieldPluginBase.php

File

src/Plugin/GraphQL/Fields/FieldPluginBase.php, line 218

Class

FieldPluginBase

Namespace

Drupal\graphql\Plugin\GraphQL\Fields

Code

protected function unwrapResult($result, ResolveInfo $info) {
  $result = array_map(function ($item) {
    return $item instanceof ValueWrapperInterface ? $item
      ->getValue() : $item;
  }, $result);
  $result = array_map(function ($item) {
    return $item instanceof MarkupInterface ? $item
      ->__toString() : $item;
  }, $result);

  // If this is a list, return the result as an array.
  $type = $info->returnType;
  if ($type instanceof ListOfType || $type instanceof NonNull && $type
    ->getWrappedType() instanceof ListOfType) {
    return $result;
  }
  return !empty($result) ? reset($result) : NULL;
}