File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
app/code/Magento/GraphQl/Controller/HttpRequestValidator Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11
11
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
12
12
use Magento \Framework \App \Request \Http ;
13
13
use Magento \GraphQl \Controller \HttpRequestValidatorInterface ;
14
+ use GraphQL \Language \AST \Node ;
15
+ use GraphQL \Language \AST \NodeKind ;
14
16
15
17
/**
16
18
* Validator to check HTTP verb for Graphql requests
@@ -29,8 +31,20 @@ public function validate(HttpRequestInterface $request) : void
29
31
/** @var Http $request */
30
32
if (false === $ request ->isPost ()) {
31
33
$ 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 ' ) {
34
48
throw new GraphQlInputException (
35
49
new \Magento \Framework \Phrase ('Mutation requests allowed only for POST requests ' )
36
50
);
You can’t perform that action at this time.
0 commit comments