You are here

public function DataProducerProxy::resolve in GraphQL 8.4

Resolve field value.

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

Throws

\Drupal\Component\Plugin\Exception\PluginException

Overrides ResolverInterface::resolve

File

src/Plugin/GraphQL/DataProducer/DataProducerProxy.php, line 164

Class

DataProducerProxy
A proxy class that lazy resolves data producers and has a result cache.

Namespace

Drupal\graphql\Plugin\GraphQL\DataProducer

Code

public function resolve($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
  $plugin = $this
    ->prepare($value, $args, $context, $info, $field);
  return DeferredUtility::returnFinally($plugin, function (DataProducerPluginInterface $plugin) use ($context, $field) {
    foreach ($plugin
      ->getContexts() as $item) {

      /** @var \Drupal\Core\Plugin\Context\Context $item */
      if ($item
        ->getContextDefinition()
        ->isRequired() && !$item
        ->hasContextValue()) {
        return NULL;
      }
    }
    if ($this->cached && $plugin instanceof DataProducerPluginCachingInterface) {
      if (!!$context
        ->getServer()
        ->get('caching')) {
        return $this
          ->resolveCached($plugin, $context, $field);
      }
    }
    return $this
      ->resolveUncached($plugin, $context, $field);
  });
}