Skip to content

Commit 196ab50

Browse files
committed
ACP2E-3467: [Cloud] 500 response to empty Graphql response on 2.4.7
1 parent a76cb6e commit 196ab50

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

app/code/Magento/GraphQl/Controller/GraphQl.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
namespace Magento\GraphQl\Controller;
99

10+
use GraphQL\Error\FormattedError;
11+
use GraphQL\Error\SyntaxError;
1012
use Magento\Framework\App\Area;
1113
use Magento\Framework\App\AreaList;
1214
use Magento\Framework\App\FrontControllerInterface;
@@ -206,6 +208,11 @@ public function dispatch(RequestInterface $request): ResponseInterface
206208
);
207209
$statusCode = 200;
208210
}
211+
} catch (SyntaxError $error) {
212+
$result = [
213+
'errors' => [FormattedError::createFromException($error)],
214+
];
215+
$statusCode = 400;
209216
} catch (\Exception $error) {
210217
$result = [
211218
'errors' => [$this->graphQlError->create($error)],

dev/tests/integration/testsuite/Magento/GraphQl/Controller/GraphQlControllerTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,4 +272,14 @@ public function testDispatchWithOptions(): void
272272
self::assertEquals(204, $response->getStatusCode());
273273
self::assertEmpty($response->getContent());
274274
}
275+
276+
public function testDispatchWithoutQuery(): void
277+
{
278+
$this->request->setPathInfo('/graphql');
279+
$this->request->setMethod('GET');
280+
$response = $this->graphql->dispatch($this->request);
281+
self::assertEquals(400, $response->getStatusCode());
282+
$output = $this->jsonSerializer->unserialize($response->getContent());
283+
self::assertNotEmpty($output['errors']);
284+
}
275285
}

0 commit comments

Comments
 (0)