protected function DataProducerProxy::prepare in GraphQL 8.4
Instantiate the actual data producer and populate it with context values.
Parameters
mixed $value:
mixed $args:
\Drupal\graphql\GraphQL\Execution\ResolveContext $context:
\GraphQL\Type\Definition\ResolveInfo $info:
\Drupal\graphql\GraphQL\Execution\FieldContext $field:
Return value
\GraphQL\Deferred|\Drupal\graphql\Plugin\DataProducerPluginInterface
Throws
\Drupal\Component\Plugin\Exception\PluginException
\Exception
1 call to DataProducerProxy::prepare()
- DataProducerProxy::resolve in src/
Plugin/ GraphQL/ DataProducer/ DataProducerProxy.php - Resolve field value.
File
- src/
Plugin/ GraphQL/ DataProducer/ DataProducerProxy.php, line 199
Class
- DataProducerProxy
- A proxy class that lazy resolves data producers and has a result cache.
Namespace
Drupal\graphql\Plugin\GraphQL\DataProducerCode
protected function prepare($value, $args, ResolveContext $context, ResolveInfo $info, FieldContext $field) {
/** @var \Drupal\graphql\Plugin\DataProducerPluginInterface $plugin */
$plugin = $this->pluginManager
->createInstance($this->id, $this->config);
$contexts = $plugin
->getContextDefinitions();
$values = [];
foreach ($contexts as $name => $definition) {
$mapper = $this->mapping[$name] ?? NULL;
if ($definition
->isRequired() && empty($mapper)) {
throw new \LogicException(sprintf('Missing input mapper for argument %s.', $name));
}
if (!empty($mapper) && !$mapper instanceof ResolverInterface) {
throw new \Exception(sprintf('Invalid input mapper for argument %s.', $name));
}
$values[$name] = !empty($mapper) ? $mapper
->resolve($value, $args, $context, $info, $field) : NULL;
}
$values = DeferredUtility::waitAll($values);
return DeferredUtility::returnFinally($values, function ($values) use ($plugin) {
foreach ($values as $name => $value) {
$plugin
->setContextValue($name, $value);
}
return $plugin;
});
}