File tree Expand file tree Collapse file tree 5 files changed +34
-20
lines changed
lib/internal/Magento/Framework/GraphQl/Query Expand file tree Collapse file tree 5 files changed +34
-20
lines changed Original file line number Diff line number Diff line change @@ -41,6 +41,7 @@ class GraphQl implements FrontControllerInterface
41
41
/**
42
42
* @var \Magento\Framework\Webapi\Response
43
43
* @deprecated 100.3.2
44
+ * @see was only added to fix the constructor
44
45
*/
45
46
private $ response ;
46
47
@@ -66,7 +67,8 @@ class GraphQl implements FrontControllerInterface
66
67
67
68
/**
68
69
* @var ContextInterface
69
- * @deprecated 100.3.3 $contextFactory is used for creating Context object
70
+ * @deprecated 100.3.3
71
+ * @see $contextFactory is used for creating Context object
70
72
*/
71
73
private $ resolverContext ;
72
74
@@ -185,12 +187,14 @@ public function dispatch(RequestInterface $request): ResponseInterface
185
187
186
188
// We must extract queried field names to avoid instantiation of unnecessary fields in webonyx schema
187
189
// Temporal coupling is required for performance optimization
188
- $ this ->queryFields ->setQuery ($ query , $ variables );
190
+ $ data ['parsedQuery ' ] =
191
+ \GraphQL \Language \Parser::parse (new \GraphQL \Language \Source ($ query ?: '' , 'GraphQL ' ));
192
+ $ this ->queryFields ->setQuery ($ data ['parsedQuery ' ], $ variables );
189
193
$ schema = $ this ->schemaGenerator ->generate ();
190
194
191
195
$ result = $ this ->queryProcessor ->process (
192
196
$ schema ,
193
- $ query ,
197
+ $ data [ ' parsedQuery ' ] ,
194
198
$ this ->contextFactory ->create (),
195
199
$ data ['variables ' ] ?? []
196
200
);
Original file line number Diff line number Diff line change 8
8
namespace Magento \GraphQl \Helper \Query \Logger ;
9
9
10
10
use GraphQL \Error \SyntaxError ;
11
+ use GraphQL \Language \AST \DocumentNode ;
11
12
use GraphQL \Language \AST \Node ;
12
13
use GraphQL \Language \AST \NodeKind ;
13
14
use GraphQL \Language \Parser ;
@@ -43,7 +44,7 @@ public function getLogData(
43
44
$ logData = array_merge ($ logData , $ this ->gatherRequestInformation ($ request ));
44
45
45
46
try {
46
- $ complexity = $ this ->getFieldCount ($ data ['query ' ] ?? '' );
47
+ $ complexity = $ this ->getFieldCount ($ data ['parsedQuery ' ] ?? $ data [ ' query ' ] ?? '' );
47
48
$ logData [LoggerInterface::COMPLEXITY ] = $ complexity ;
48
49
if ($ schema ) {
49
50
$ logData = array_merge ($ logData , $ this ->gatherQueryInformation ($ schema ));
@@ -114,18 +115,20 @@ private function gatherResponseInformation(HttpResponse $response) : array
114
115
*
115
116
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
116
117
*
117
- * @param string $query
118
+ * @param DocumentNode| string $query
118
119
* @return int
119
120
* @throws SyntaxError
120
- * @throws / Exception
121
+ * @throws \ Exception
121
122
*/
122
- private function getFieldCount (string $ query ): int
123
+ private function getFieldCount (DocumentNode | string $ query ): int
123
124
{
124
125
if (!empty ($ query )) {
125
126
$ totalFieldCount = 0 ;
126
- $ queryAst = Parser::parse (new Source ($ query ?: '' , 'GraphQL ' ));
127
+ if (is_string ($ query )) {
128
+ $ query = Parser::parse (new Source ($ query , 'GraphQL ' ));
129
+ }
127
130
Visitor::visit (
128
- $ queryAst ,
131
+ $ query ,
129
132
[
130
133
'leave ' => [
131
134
NodeKind::FIELD => function (Node $ node ) use (&$ totalFieldCount ) {
Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Framework \GraphQl \Query ;
9
9
10
+ use GraphQL \Language \AST \DocumentNode ;
10
11
use GraphQL \Language \AST \Node ;
11
12
use GraphQL \Language \AST \NodeKind ;
12
13
@@ -23,7 +24,7 @@ class Fields
23
24
/**
24
25
* Set Query for extracting list of fields.
25
26
*
26
- * @param string $query
27
+ * @param DocumentNode| string $query
27
28
* @param array|null $variables
28
29
*
29
30
* @return void
@@ -32,9 +33,11 @@ public function setQuery($query, array $variables = null)
32
33
{
33
34
$ queryFields = [];
34
35
try {
35
- $ queryAst = \GraphQL \Language \Parser::parse (new \GraphQL \Language \Source ($ query ?: '' , 'GraphQL ' ));
36
+ if (is_string ($ query )) {
37
+ $ query = \GraphQL \Language \Parser::parse (new \GraphQL \Language \Source ($ query ?: '' , 'GraphQL ' ));
38
+ }
36
39
\GraphQL \Language \Visitor::visit (
37
- $ queryAst ,
40
+ $ query ,
38
41
[
39
42
'leave ' => [
40
43
NodeKind::NAME => function (Node $ node ) use (&$ queryFields ) {
Original file line number Diff line number Diff line change 7
7
8
8
namespace Magento \Framework \GraphQl \Query ;
9
9
10
- use GraphQL \Language \AST \Node ;
10
+ use GraphQL \Language \AST \DocumentNode ;
11
11
use GraphQL \Language \AST \NodeKind ;
12
12
use GraphQL \Language \Parser ;
13
13
use GraphQL \Language \Source ;
@@ -80,19 +80,22 @@ public function execute(): void
80
80
* This is necessary for performance optimization, as extremely large queries require a substantial
81
81
* amount of time to fully validate and can affect server performance.
82
82
*
83
- * @param string $query
83
+ * @param DocumentNode| string $query
84
84
* @throws GraphQlInputException
85
85
*/
86
- public function validateFieldCount (string $ query ): void
86
+ public function validateFieldCount (DocumentNode | string $ query ): void
87
87
{
88
88
if (!empty ($ query )) {
89
89
$ totalFieldCount = 0 ;
90
- $ queryAst = Parser::parse (new Source ($ query ?: '' , 'GraphQL ' ));
90
+ if (is_string ($ query )) {
91
+ $ query = Parser::parse (new Source ($ query , 'GraphQL ' ));
92
+ }
93
+
91
94
Visitor::visit (
92
- $ queryAst ,
95
+ $ query ,
93
96
[
94
97
'leave ' => [
95
- NodeKind::FIELD => function (Node $ node ) use (&$ totalFieldCount ) {
98
+ NodeKind::FIELD => function () use (&$ totalFieldCount ) {
96
99
$ totalFieldCount ++;
97
100
}
98
101
]
Original file line number Diff line number Diff line change 9
9
10
10
use GraphQL \Error \DebugFlag ;
11
11
use GraphQL \GraphQL ;
12
+ use GraphQL \Language \AST \DocumentNode ;
12
13
use Magento \Framework \GraphQl \Exception \ExceptionFormatter ;
13
14
use Magento \Framework \GraphQl \Exception \GraphQlInputException ;
14
15
use Magento \Framework \GraphQl \Query \Resolver \ContextInterface ;
@@ -54,7 +55,7 @@ public function __construct(
54
55
* Process a GraphQl query according to defined schema
55
56
*
56
57
* @param Schema $schema
57
- * @param string $source
58
+ * @param DocumentNode| string $source
58
59
* @param ContextInterface|null $contextValue
59
60
* @param array|null $variableValues
60
61
* @param string|null $operationName
@@ -63,7 +64,7 @@ public function __construct(
63
64
*/
64
65
public function process (
65
66
Schema $ schema ,
66
- string $ source ,
67
+ DocumentNode | string $ source ,
67
68
ContextInterface $ contextValue = null ,
68
69
array $ variableValues = null ,
69
70
string $ operationName = null
You can’t perform that action at this time.
0 commit comments