Skip to content

Commit 4c8cd50

Browse files
author
hwyu@adobe.com
committed
Merge remote-tracking branch 'upstream/2.3.7-develop' into MC-38715
2 parents 4f056c0 + 263f508 commit 4c8cd50

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

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

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use Magento\Framework\GraphQl\Exception\GraphQlInputException;
1212
use Magento\Framework\App\Request\Http;
1313
use Magento\GraphQl\Controller\HttpRequestValidatorInterface;
14+
use GraphQL\Language\AST\Node;
15+
use GraphQL\Language\AST\NodeKind;
1416

1517
/**
1618
* Validator to check HTTP verb for Graphql requests
@@ -29,8 +31,20 @@ public function validate(HttpRequestInterface $request) : void
2931
/** @var Http $request */
3032
if (false === $request->isPost()) {
3133
$query = $request->getParam('query', '');
32-
// The easiest way to determine mutations without additional parsing
33-
if (strpos(trim($query), 'mutation') === 0) {
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+
}
43+
]
44+
]
45+
);
46+
47+
if (strtolower($operationType) === 'mutation') {
3448
throw new GraphQlInputException(
3549
new \Magento\Framework\Phrase('Mutation requests allowed only for POST requests')
3650
);

0 commit comments

Comments
 (0)