Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/bundle/DependencyInjection/IbexaGraphQLExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public function prepend(ContainerBuilder $container)
'dir' => $container->getParameter('kernel.project_dir') . self::SCHEMA_DIR_PATH,
];
$container->prependExtensionConfig('overblog_graphql', $graphQLConfig);
$container->prependExtensionConfig('monolog', ['channels' => ['graphql']]);
}

/**
Expand Down
4 changes: 4 additions & 0 deletions src/bundle/Resources/config/services/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ services:
$provider: '@ibexa.siteaccess.provider'
$siteAccessGroups: '%ibexa.site_access.groups%'

Ibexa\GraphQL\EventListener\ArgumentsExceptionListener:
arguments:
$logger: '@monolog.logger.graphql'

Ibexa\GraphQL\Mapper\ContentImageAssetMapperStrategy:
arguments:
$assetMapper: '@Ibexa\Core\FieldType\ImageAsset\AssetMapper'
Expand Down
46 changes: 46 additions & 0 deletions src/lib/EventListener/ArgumentsExceptionListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

/**
* @copyright Copyright (C) Ibexa AS. All rights reserved.
* @license For full copyright and license information view LICENSE file distributed with this source code.
*/
namespace Ibexa\GraphQL\EventListener;

use Ibexa\GraphQL\DataLoader\Exception\ArgumentsException;
use Overblog\GraphQLBundle\Event\ErrorFormattingEvent;
use Overblog\GraphQLBundle\Event\Events;
use Psr\Log\LoggerInterface;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

final class ArgumentsExceptionListener implements EventSubscriberInterface
{
private LoggerInterface $logger;

public function __construct(LoggerInterface $logger)
{
$this->logger = $logger;
}

public static function getSubscribedEvents(): array
{
return [
Events::ERROR_FORMATTING => ['onErrorFormatting', 10],
];
}

public function onErrorFormatting(ErrorFormattingEvent $event): void
{
$exception = $event->getError()->getPrevious();

if (!$exception instanceof ArgumentsException) {
return;
}

$this->logger->critical(
sprintf('[GraphQL] %s: %s', ArgumentsException::class, $exception->getMessage()),
['exception' => $exception]
);

$event->stopPropagation();
}
}
Loading