Skip to content

Commit 3e5d6f6

Browse files
committed
MC-40920: Empty request to graphql in 2.4.2 throws 500 instead of previous 200
1 parent 516acb2 commit 3e5d6f6

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,25 @@ public function validate(HttpRequestInterface $request) : void
3131
/** @var Http $request */
3232
if (false === $request->isPost()) {
3333
$query = $request->getParam('query', '');
34-
$operationType = null;
35-
$queryAst = \GraphQL\Language\Parser::parse(new \GraphQL\Language\Source($query ?: '', 'GraphQL'));
36-
\GraphQL\Language\Visitor::visit(
37-
$queryAst,
38-
[
39-
'leave' => [
40-
NodeKind::OPERATION_DEFINITION => function (Node $node) use (&$operationType) {
41-
$operationType = $node->operation;
42-
}
34+
if (!empty($query)) {
35+
$operationType = null;
36+
$queryAst = \GraphQL\Language\Parser::parse(new \GraphQL\Language\Source($query ?: '', 'GraphQL'));
37+
\GraphQL\Language\Visitor::visit(
38+
$queryAst,
39+
[
40+
'leave' => [
41+
NodeKind::OPERATION_DEFINITION => function (Node $node) use (&$operationType) {
42+
$operationType = $node->operation;
43+
}
44+
]
4345
]
44-
]
45-
);
46-
47-
if (strtolower($operationType) === 'mutation') {
48-
throw new GraphQlInputException(
49-
new \Magento\Framework\Phrase('Mutation requests allowed only for POST requests')
5046
);
47+
48+
if (strtolower($operationType) === 'mutation') {
49+
throw new GraphQlInputException(
50+
new \Magento\Framework\Phrase('Mutation requests allowed only for POST requests')
51+
);
52+
}
5153
}
5254
}
5355
}

0 commit comments

Comments
 (0)