b374k
m1n1 1.01
Apache/2.4.41 (Ubuntu)
Linux vmi616275.contaboserver.net 5.4.0-84-generic #94-Ubuntu SMP Thu Aug 26 20:27:37 UTC 2021 x86_64
uid=33(www-data) gid=33(www-data) groups=33(www-data)
server ip : 62.171.164.128 | your ip : 127.0.0.1
safemode OFF
 >  / home / dev2.destoffenstraat.com / vendor / magento / framework / GraphQl / Query /
Filename/home/dev2.destoffenstraat.com/vendor/magento/framework/GraphQl/Query/BatchResolverWrapper.php
Size3.32 kb
Permissionrw-r--r--
Ownerroot : root
Create time17-Aug-2025 10:26
Last modified07-Jan-2021 21:08
Last accessed23-Aug-2025 03:56
Actionsedit | rename | delete | download (gzip)
Viewtext | code | image
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\GraphQl\Query;

use Magento\Framework\GraphQl\Config\Element\Field;
use Magento\Framework\GraphQl\Query\Resolver\BatchRequestItemInterface;
use Magento\Framework\GraphQl\Query\Resolver\BatchResolverInterface;
use Magento\Framework\GraphQl\Query\Resolver\BatchResponse;
use Magento\Framework\GraphQl\Query\Resolver\ResolveRequest;
use Magento\Framework\GraphQl\Query\Resolver\ValueFactory;
use Magento\Framework\GraphQl\Schema\Type\ResolveInfo;

/**
* Wrapper containing batching logic for BatchResolverInterface.
*/
class BatchResolverWrapper implements ResolverInterface
{
/**
* @var BatchResolverInterface
*/
private $resolver;

/**
* @var ValueFactory
*/
private $valueFactory;

/**
* @var \Magento\Framework\GraphQl\Query\Resolver\ContextInterface|null
*/
private $context;

/**
* @var Field|null
*/
private $field;

/**
* @var BatchRequestItemInterface[]
*/
private $request = [];

/**
* @var BatchResponse|null
*/
private $response;

/**
* BatchResolverWrapper constructor.
* @param BatchResolverInterface $resolver
* @param ValueFactory $valueFactory
*/
public function __construct(BatchResolverInterface $resolver, ValueFactory $valueFactory)
{
$this->resolver = $resolver;
$this->valueFactory = $valueFactory;
}

/**
* Clear aggregated data.
*
* @return void
*/
private function clearAggregated(): void
{
$this->response = null;
$this->request = null;
$this->context = null;
$this->field = null;
}

/**
* Find resolved data for given request.
*
* @param BatchRequestItemInterface $item
* @throws \Throwable
* @return mixed
*/
private function findResolvedFor(BatchRequestItemInterface $item)
{
try {
return $this->resolveFor($item);
} catch (\Throwable $exception) {
$this->clearAggregated();
throw $exception;
}
}

/**
* Resolve branch/leaf for given item.
*
* @param BatchRequestItemInterface $item
* @return mixed|\Magento\Framework\GraphQl\Query\Resolver\Value
* @throws \Throwable
*/
private function resolveFor(BatchRequestItemInterface $item)
{
if (!$this->request) {
throw new \RuntimeException('Unknown batch request item');
}

if (!$this->response) {
$this->response = $this->resolver->resolve($this->context, $this->field, $this->request);
}

return $this->response->findResponseFor($item);
}

/**
* @inheritDoc
*/
public function resolve(Field $field, $context, ResolveInfo $info, array $value = null, array $args = null)
{
if ($this->response) {
$this->clearAggregated();
}

$item = new ResolveRequest($field, $context, $info, $value, $args);
$this->request[] = $item;
$this->context = $context;
$this->field = $field;

return $this->valueFactory->create(
function () use ($item) {
return $this->findResolvedFor($item);
}
);
}
}