Composite.php in GraphQL 8.4
File
src/GraphQL/Resolver/Composite.php
View source
<?php
namespace Drupal\graphql\GraphQL\Resolver;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use GraphQL\Executor\Promise\Adapter\SyncPromise;
use Drupal\graphql\GraphQL\Utility\DeferredUtility;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use GraphQL\Type\Definition\ResolveInfo;
class Composite implements ResolverInterface {
protected $resolvers = [];
public function __construct(array $resolvers) {
$this->resolvers = $resolvers;
}
public function add(ResolverInterface $resolver) : void {
$this->resolvers[] = $resolver;
}
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;
}
}
Classes
Name |
Description |
Composite |
Resolves by calling a chain of resolvers after each other. |