Skip to content
Merged
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 phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ parameters:
-
message: '#Parameter .* of class GraphQL\\Error\\Error constructor expects#'
path: src/Exceptions/WebonyxErrorHandler.php
- '#Call to an undefined method GraphQL\\Error\\ClientAware::getMessage()#'
#-
# message: '#If condition is always true#'
# path: src/Middlewares/SecurityFieldMiddleware.php
Expand Down
2 changes: 1 addition & 1 deletion src/Exceptions/WebonyxErrorHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static function errorHandler(array $errors, callable $formatter): array
// Let's build a new error at the same spot than the aggregated one, but for the wrapped exception.
$extensions = $clientAware instanceof GraphQLExceptionInterface ? $clientAware->getExtensions() : [];

return new Error($error->getMessage(), $error->getNodes(), $error->getSource(), $error->getPositions(), $error->getPath(), $clientAware, $extensions);
return new Error($clientAware->getMessage(), $error->getNodes(), $error->getSource(), $error->getPositions(), $error->getPath(), $clientAware, $extensions);
}, $exceptions);

$formattedInnerErrors = self::errorHandler($innerErrors, $formatter);
Expand Down
14 changes: 3 additions & 11 deletions tests/Exceptions/ErrorHandlerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,24 +26,16 @@ public function testErrorFormatter()
public function testErrorHandler()
{
$exception = new GraphQLException('foo', 0, null, 'MyCategory', ['field' => 'foo']);
$error = new Error('foo', null, null, null, null, $exception);
$error = new Error('bar', null, null, null, null, $exception);
$aggregateException = new GraphQLAggregateException();
$aggregateException->add($exception);
$aggregateException->add($exception);
$aggregateError = new Error('foo', null, null, null, null, $aggregateException);
$aggregateError = new Error('bar', null, null, null, null, $aggregateException);
$formattedError = WebonyxErrorHandler::errorHandler([$error, $aggregateError], [WebonyxErrorHandler::class, 'errorFormatter']);

$expectedError = [
'message' => 'foo',
'extensions' => [
'category' => 'MyCategory',
'field' => 'foo'
]
];

$this->assertSame([
[
'message' => 'foo',
'message' => 'bar',
'extensions' => [
'category' => 'MyCategory',
'field' => 'foo'
Expand Down