You are here

class SourceContext in GraphQL 8.4

Resolves by setting the value as context with the given name.

Hierarchy

Expanded class hierarchy of SourceContext

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

File

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

Namespace

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

  /**
   * Name of the context.
   *
   * @var string
   */
  protected $name;

  /**
   * Source resolver.
   *
   * @var mixed
   */
  protected $source;

  /**
   * SourceContext constructor.
   *
   * @param string $name
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface|null $source
   */
  public function __construct($name, ResolverInterface $source = NULL) {
    $this->name = $name;
    $this->source = $source;
  }

  /**
   * {@inheritdoc}
   */
  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;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
SourceContext::$name protected property Name of the context.
SourceContext::$source protected property Source resolver.
SourceContext::resolve public function Resolve values for the fields. Overrides ResolverInterface::resolve
SourceContext::__construct public function SourceContext constructor.