Skip to content

Commit 29fa29d

Browse files
authored
Merge pull request #6178 from christianbeeznest/fixes-updates82
Internal: Implement LoggingExecutor for GraphQL error reporting
2 parents d735d3a + e6c0be4 commit 29fa29d

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/* For licensing terms, see /license.txt */
6+
7+
namespace Chamilo\CoreBundle\GraphQL;
8+
9+
use ApiPlatform\GraphQl\ExecutorInterface;
10+
use GraphQL\GraphQL;
11+
use GraphQL\Type\Schema;
12+
use GraphQL\Executor\ExecutionResult;
13+
use Psr\Log\LoggerInterface;
14+
15+
class LoggingExecutor implements ExecutorInterface
16+
{
17+
private LoggerInterface $logger;
18+
19+
public function __construct(LoggerInterface $logger)
20+
{
21+
$this->logger = $logger;
22+
}
23+
24+
public function executeQuery(
25+
Schema $schema,
26+
$source,
27+
$rootValue = null,
28+
$context = null,
29+
array $variableValues = null,
30+
string $operationName = null,
31+
callable $fieldResolver = null,
32+
array $validationRules = null
33+
): ExecutionResult {
34+
$result = GraphQL::executeQuery(
35+
$schema,
36+
$source,
37+
$rootValue,
38+
$context,
39+
$variableValues,
40+
$operationName,
41+
$fieldResolver,
42+
$validationRules
43+
);
44+
45+
if (!empty($result->errors)) {
46+
foreach ($result->errors as $error) {
47+
$msg = '[GraphQL Error] '.$error->getMessage();
48+
error_log($msg);
49+
50+
$this->logger->error($msg, [
51+
'debugMessage' => $error->getPrevious()?->getMessage() ?? null,
52+
'path' => $error->getPath(),
53+
'locations' => $error->getLocations(),
54+
'extensions' => $error->getExtensions(),
55+
]);
56+
}
57+
}
58+
59+
return $result;
60+
}
61+
}

src/CoreBundle/Resources/config/services.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,3 +122,8 @@ services:
122122
Chamilo\CoreBundle\Service\AI\DeepSeekAiProvider:
123123
factory: [ '@Chamilo\CoreBundle\Service\AI\AiProviderFactory', 'getProvider' ]
124124
arguments: [ 'deepseek' ]
125+
126+
api_platform.graphql.executor:
127+
class: Chamilo\CoreBundle\GraphQL\LoggingExecutor
128+
arguments:
129+
$logger: '@logger'

0 commit comments

Comments
 (0)