You are here

class Composite in GraphQL 8.4

Resolves by calling a chain of resolvers after each other.

Hierarchy

Expanded class hierarchy of Composite

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

File

src/GraphQL/Resolver/Composite.php, line 14

Namespace

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

  /**
   * DataProducerProxy objects.
   *
   * @var array
   */
  protected $resolvers = [];

  /**
   * Composite constructor.
   *
   * @param array $resolvers
   */
  public function __construct(array $resolvers) {
    $this->resolvers = $resolvers;
  }

  /**
   * Add one more producer.
   *
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface $resolver
   *   DataProducerProxy object.
   */
  public function add(ResolverInterface $resolver) : void {
    $this->resolvers[] = $resolver;
  }

  /**
   * {@inheritdoc}
   */
  public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
    $resolvers = $this->resolvers;
    while ($resolver = array_shift($resolvers)) {
      $value = $resolver
        ->resolve($value, $args, $context, $info, $field);
      if ($value instanceof SyncPromise) {
        return DeferredUtility::returnFinally($value, function ($value) use ($resolvers, $args, $context, $info, $field) {
          return isset($value) ? (new Composite($resolvers))
            ->resolve($value, $args, $context, $info, $field) : NULL;
        });
      }
    }
    return $value;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Composite::$resolvers protected property DataProducerProxy objects.
Composite::add public function Add one more producer.
Composite::resolve public function Resolve values for the fields. Overrides ResolverInterface::resolve
Composite::__construct public function Composite constructor.