You are here

class Path in GraphQL 8.4

Resolves a property path.

@todo Delete this resolver. This is a plugin already.

Hierarchy

Expanded class hierarchy of Path

File

src/GraphQL/Resolver/Path.php, line 20

Namespace

Drupal\graphql\GraphQL\Resolver
View source
class Path implements ResolverInterface {
  use TypedDataTrait;
  use DataFetcherTrait;

  /**
   * Name of the context.
   *
   * @var string|\Drupal\Core\TypedData\DataDefinitionInterface
   */
  protected $type;

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

  /**
   * Resolver.
   *
   * @var mixed
   */
  protected $value;

  /**
   * Path constructor.
   *
   * @param string $type
   * @param mixed $path
   * @param \Drupal\graphql\GraphQL\Resolver\ResolverInterface|null $value
   */
  public function __construct($type, $path, ResolverInterface $value = NULL) {
    $this->type = $type;
    $this->path = $path;
    $this->value = $value;
  }

  /**
   * {@inheritdoc}
   */
  public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
    $value = $this->value ?? new ParentValue();
    $value = $value
      ->resolve($value, $args, $context, $info, $field);
    $metadata = new BubbleableMetadata();
    $type = $this->type instanceof DataDefinitionInterface ? $this->type : DataDefinition::create($this->type);
    $data = $this
      ->getTypedDataManager()
      ->create($type, $value);
    $output = $this
      ->getDataFetcher()
      ->fetchDataByPropertyPath($data, $this->path, $metadata)
      ->getValue();
    $context
      ->addCacheableDependency($metadata);
    if ($output instanceof CacheableDependencyInterface) {
      $context
        ->addCacheableDependency($output);
    }
    return $output;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DataFetcherTrait::$dataFetcher protected property The data fetcher.
DataFetcherTrait::getDataFetcher public function Gets the data fetcher.
DataFetcherTrait::setDataFetcher public function Sets the data fetcher.
Path::$path protected property Source resolver.
Path::$type protected property Name of the context.
Path::$value protected property Resolver.
Path::resolve public function Resolve values for the fields. Overrides ResolverInterface::resolve
Path::__construct public function Path constructor.
TypedDataTrait::$typedDataManager protected property The typed data manager used for creating the data types.
TypedDataTrait::getTypedDataManager public function Gets the typed data manager. 2
TypedDataTrait::setTypedDataManager public function Sets the typed data manager. 2