Skip to content

Commit 1289e1b

Browse files
committed
B2B-2606: Graphql Parser called at least 3 times per request
1 parent bac0677 commit 1289e1b

File tree

5 files changed

+12
-11
lines changed

5 files changed

+12
-11
lines changed

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -181,22 +181,25 @@ public function dispatch(RequestInterface $request): ResponseInterface
181181

182182
$statusCode = 200;
183183
$jsonResult = $this->jsonFactory->create();
184+
$data = $this->getDataFromRequest($request);
184185
$result = [];
185186

186187
$schema = null;
187188
try {
188189
/** @var Http $request */
189190
$this->requestProcessor->validateRequest($request);
190-
$data = $this->getDataFromRequest($request);
191+
$query = $data['query'] ?? '';
192+
$parsedQuery = $this->queryParser->parse($query);
193+
$data['parsedQuery'] = $parsedQuery;
191194

192195
// We must extract queried field names to avoid instantiation of unnecessary fields in webonyx schema
193196
// Temporal coupling is required for performance optimization
194-
$this->queryFields->setQuery($data['parsedQuery'], $data['variables'] ?? null);
197+
$this->queryFields->setQuery($parsedQuery, $data['variables'] ?? null);
195198
$schema = $this->schemaGenerator->generate();
196199

197200
$result = $this->queryProcessor->process(
198201
$schema,
199-
$data['parsedQuery'],
202+
$parsedQuery,
200203
$this->contextFactory->create(),
201204
$data['variables'] ?? []
202205
);
@@ -237,11 +240,9 @@ private function getDataFromRequest(RequestInterface $request): array
237240
$data['variables'] = is_array($data['variables']) ?
238241
$data['variables'] : null;
239242
} else {
240-
$data = [];
243+
return [];
241244
}
242-
$query = $data['query'] ?? '';
243-
$parsedQuery = $this->queryParser->parse($query);
244-
$data['parsedQuery'] = $parsedQuery;
245+
245246
return $data;
246247
}
247248
}

app/code/Magento/GraphQl/Helper/Query/Logger/LogData.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ private function gatherResponseInformation(HttpResponse $response) : array
133133
* @throws SyntaxError
134134
* @throws \Exception
135135
*/
136-
private function getFieldCount(DocumentNode|string $query): int
136+
private function getFieldCount($query): int
137137
{
138138
if (!empty($query)) {
139139
$totalFieldCount = 0;

lib/internal/Magento/Framework/GraphQl/Query/Fields.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ public function __construct(QueryParser $queryParser = null)
4343
*
4444
* @return void
4545
*/
46-
public function setQuery(DocumentNode|string $query, array $variables = null)
46+
public function setQuery($query, array $variables = null)
4747
{
4848
$queryFields = [];
4949
try {

lib/internal/Magento/Framework/GraphQl/Query/QueryComplexityLimiter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public function execute(): void
9090
* @param DocumentNode|string $query
9191
* @throws GraphQlInputException
9292
*/
93-
public function validateFieldCount(DocumentNode|string $query): void
93+
public function validateFieldCount($query): void
9494
{
9595
if (!empty($query)) {
9696
$totalFieldCount = 0;

lib/internal/Magento/Framework/GraphQl/Query/QueryProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function __construct(
7373
*/
7474
public function process(
7575
Schema $schema,
76-
DocumentNode|string $source,
76+
$source,
7777
ContextInterface $contextValue = null,
7878
array $variableValues = null,
7979
string $operationName = null

0 commit comments

Comments
 (0)