You are here

public function ResolveContext::getContextValue in GraphQL 8.4

Get a contextual value for the current field.

Allows field resolvers to inherit contextual values from their ancestors.

Parameters

\GraphQL\Type\Definition\ResolveInfo $info: The resolve info object.

string $name: The name of the context.

Return value

mixed The current value of the given context or NULL if it's not set.

File

src/GraphQL/Execution/ResolveContext.php, line 184

Class

ResolveContext
Context that is provided during resolving the GraphQL tree.

Namespace

Drupal\graphql\GraphQL\Execution

Code

public function getContextValue(ResolveInfo $info, $name) {
  $path = $info->path;
  do {
    $key = implode('.', $path);
    if (isset($this->contexts[$key]) && array_key_exists($name, $this->contexts[$key])) {
      return $this->contexts[$key][$name];
    }
    array_pop($path);
  } while (count($path));
  return NULL;
}