You are here

public function Path::resolve in GraphQL 8.4

Resolve values for the fields.

Parameters

mixed $value:

mixed $args:

\Drupal\graphql\GraphQL\Execution\ResolveContext $context:

\GraphQL\Type\Definition\ResolveInfo $info:

\Drupal\graphql\GraphQL\Execution\FieldContext $field:

Return value

mixed

Overrides ResolverInterface::resolve

File

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

Class

Path
Resolves a property path.

Namespace

Drupal\graphql\GraphQL\Resolver

Code

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;
}