protected function FieldPluginBase::resolveDeferred in GraphQL 8.3
1 call to FieldPluginBase::resolveDeferred()
- FieldPluginBase::resolve in src/
Plugin/ GraphQL/ Fields/ FieldPluginBase.php
File
- src/
Plugin/ GraphQL/ Fields/ FieldPluginBase.php, line 153
Class
Namespace
Drupal\graphql\Plugin\GraphQL\FieldsCode
protected function resolveDeferred(callable $callback, $value, array $args, ResolveContext $context, ResolveInfo $info) {
$isLanguageAware = $this
->isLanguageAwareField();
$languageContext = $this
->getLanguageContext();
$renderContext = new RenderContext();
$executor = function () use ($callback, $renderContext, $value, $args, $context, $info) {
return $this
->getRenderer()
->executeInRenderContext($renderContext, function () use ($callback, $value, $args, $context, $info) {
$result = $callback($value, $args, $context, $info);
if ($result instanceof \Generator) {
$result = iterator_to_array($result);
}
return $result;
});
};
$result = $isLanguageAware ? $languageContext
->executeInLanguageContext($executor, $context
->getContext('language', $info)) : $executor();
if (!$renderContext
->isEmpty() && $info->operation->operation === 'query') {
$context
->addCacheableDependency($renderContext
->pop());
}
if (is_callable($result)) {
return new Deferred(function () use ($result, $value, $args, $context, $info, $isLanguageAware, $languageContext) {
if ($isLanguageAware) {
return $languageContext
->executeInLanguageContext(function () use ($result, $value, $args, $context, $info) {
return $this
->resolveDeferred($result, $value, $args, $context, $info);
}, $context
->getContext('language', $info));
}
return $this
->resolveDeferred($result, $value, $args, $context, $info);
});
}
// Only collect cache metadata if this is a query. All other operation types
// are not cacheable anyways.
if ($info->operation->operation === 'query') {
$dependencies = $this
->getCacheDependencies($result, $value, $args, $context, $info);
foreach ($dependencies as $dependency) {
$context
->addCacheableDependency($dependency);
}
}
return $this
->unwrapResult($result, $info);
}