Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Log graphQL Errors from result #379

Open
mauriau opened this issue Sep 10, 2018 · 0 comments
Open

Log graphQL Errors from result #379

mauriau opened this issue Sep 10, 2018 · 0 comments
Labels

Comments

@mauriau
Copy link

mauriau commented Sep 10, 2018

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']));
        }
    }
}

@mauriau mauriau changed the title Log graphql Errors from results Log graphql Errors from result Sep 10, 2018
@mauriau mauriau changed the title Log graphql Errors from result Log graphQL Errors from result Sep 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants