SourceContext.php in GraphQL 8.4
File
src/GraphQL/Resolver/SourceContext.php
View source
<?php
namespace Drupal\graphql\GraphQL\Resolver;
use Drupal\graphql\GraphQL\Execution\FieldContext;
use Drupal\graphql\GraphQL\Execution\ResolveContext;
use GraphQL\Type\Definition\ResolveInfo;
class SourceContext implements ResolverInterface {
protected $name;
protected $source;
public function __construct($name, ResolverInterface $source = NULL) {
$this->name = $name;
$this->source = $source;
}
public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
$source = $this->source ?? new ParentValue();
$context = $source
->resolve($value, $args, $context, $info, $field);
$field
->setContextValue($this->name, $context);
return $context;
}
}
Classes
Name |
Description |
SourceContext |
Resolves by setting the value as context with the given name. |