You are here

class Map in GraphQL 8.4

Execute a resolver for each item in the given list.

Hierarchy

Expanded class hierarchy of Map

1 file declares its use of Map
ResolverBuilder.php in src/GraphQL/ResolverBuilder.php

File

src/GraphQL/Resolver/Map.php, line 12

Namespace

Drupal\graphql\GraphQL\Resolver
View source
class Map implements ResolverInterface {

  /**
   * Resolver to tap.
   *
   * @var mixed
   */
  protected $resolver;

  /**
   * Map constructor.
   *
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $resolver
   */
  public function __construct(ResolverInterface $resolver) {
    $this->resolver = $resolver;
  }

  /**
   * {@inheritdoc}
   */
  public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
    if (!is_iterable($value)) {
      return NULL;
    }
    $array = is_array($value) ? $value : iterator_to_array($value);
    return array_map(function ($item) use ($args, $context, $info, $field) {
      return $this->resolver
        ->resolve($item, $args, $context, $info, $field);
    }, $array);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Map::$resolver protected property Resolver to tap.
Map::resolve public function Resolve values for the fields. Overrides ResolverInterface::resolve
Map::__construct public function Map constructor.