GraphQLBundle
GraphQLBundle copied to clipboard
Log graphQL Errors from result
Q | A |
---|---|
Bug report? | no |
Feature request? | yes |
BC Break report? | no |
RFC? | no |
Version/Branch | 0.11 |
somethings like this I will make the PR
<?php
declare(strict_types=1);
namespace Overblog\GraphQLBundle\EventListener;
use Overblog\GraphQLBundle\Error\ErrorHandler;
use Overblog\GraphQLBundle\Event\ExecutorResultEvent;
use Psr\Log\LoggerInterface;
final class ErrorHandlerListener
{
/** @var ErrorHandler */
private $errorHandler;
/** @var bool */
private $throwException;
/** @var bool */
private $debug;
/** @var LoggerInterface */
private $logger;
public function __construct(
ErrorHandler $errorHandler,
LoggerInterface $logger,
bool $throwException = false,
bool $debug = false
) {
$this->errorHandler = $errorHandler;
$this->throwException = $throwException;
$this->debug = $debug;
$this->logger = $logger;
}
public function onPostExecutor(ExecutorResultEvent $executorResultEvent): void
{
$result = $executorResultEvent->getResult();
$this->errorHandler->handleErrors($result, $this->throwException, $this->debug);
$result = $result->toArray();
if (isset($result['errors'])) {
$this->logger->error(__METHOD__.' : '.\json_encode($result['errors']));
}
}
}