class Context in GraphQL 8.4
Resolves a context value with default value support.
Hierarchy
- class \Drupal\graphql\GraphQL\Resolver\Context implements ResolverInterface
Expanded class hierarchy of Context
1 file declares its use of Context
- ResolverBuilder.php in src/
GraphQL/ ResolverBuilder.php
1 string reference to 'Context'
- ResolverBuilderTest::testFromContext in tests/
src/ Kernel/ ResolverBuilderTest.php - @covers ::context @covers ::fromContext
File
- src/
GraphQL/ Resolver/ Context.php, line 13
Namespace
Drupal\graphql\GraphQL\ResolverView source
class Context implements ResolverInterface {
/**
* Name of the context.
*
* @var mixed
*/
protected $name;
/**
* An arbitrary default value in case the context is not set.
*
* @var mixed
*/
protected $default;
/**
* Context constructor.
*
* @param string $name
* @param mixed $default
*/
public function __construct($name, $default = NULL) {
$this->name = $name;
$this->default = $default;
}
/**
* {@inheritdoc}
*/
public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
$output = $field
->getContextValue($this->name);
if (!isset($output) && !$field
->hasContextValue($this->name)) {
$output = $this->default;
}
if ($output instanceof CacheableDependencyInterface) {
$context
->addCacheableDependency($output);
}
return $output;
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
Context:: |
protected | property | An arbitrary default value in case the context is not set. | |
Context:: |
protected | property | Name of the context. | |
Context:: |
public | function |
Resolve values for the fields. Overrides ResolverInterface:: |
|
Context:: |
public | function | Context constructor. |