class Path in GraphQL 8.4
Resolves a property path.
@todo Delete this resolver. This is a plugin already.
Hierarchy
- class \Drupal\graphql\GraphQL\Resolver\Path implements ResolverInterface uses TypedDataTrait, DataFetcherTrait
Expanded class hierarchy of Path
File
- src/
GraphQL/ Resolver/ Path.php, line 20
Namespace
Drupal\graphql\GraphQL\ResolverView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
DataFetcherTrait:: |
protected | property | The data fetcher. | |
DataFetcherTrait:: |
public | function | Gets the data fetcher. | |
DataFetcherTrait:: |
public | function | Sets the data fetcher. | |
Path:: |
protected | property | Source resolver. | |
Path:: |
protected | property | Name of the context. | |
Path:: |
protected | property | Resolver. | |
Path:: |
public | function |
Resolve values for the fields. Overrides ResolverInterface:: |
|
Path:: |
public | function | Path constructor. | |
TypedDataTrait:: |
protected | property | The typed data manager used for creating the data types. | |
TypedDataTrait:: |
public | function | Gets the typed data manager. | 2 |
TypedDataTrait:: |
public | function | Sets the typed data manager. | 2 |