File tree Expand file tree Collapse file tree 2 files changed +33
-4
lines changed
app/code/Magento/GraphQl/Helper/Query/Logger
dev/tests/integration/testsuite/Magento/GraphQl/Helper/Query/Logger Expand file tree Collapse file tree 2 files changed +33
-4
lines changed Original file line number Diff line number Diff line change @@ -40,10 +40,13 @@ public function getLogData(
4040 ) : array {
4141 $ logData = [];
4242 $ logData = array_merge ($ logData , $ this ->gatherRequestInformation ($ request ));
43- if ($ schema ) {
44- $ logData = array_merge ($ logData , $ this ->gatherQueryInformation ($ schema ));
43+ $ complexity = $ this ->getFieldCount ($ data ['query ' ] ?? '' );
44+ if ($ complexity !== -1 ) {
45+ $ logData [LoggerInterface::COMPLEXITY ] = $ complexity ;
46+ if ($ schema ) {
47+ $ logData = array_merge ($ logData , $ this ->gatherQueryInformation ($ schema ));
48+ }
4549 }
46- $ logData [LoggerInterface::COMPLEXITY ] = $ this ->getFieldCount ($ data ['query ' ] ?? '' );
4750 if ($ response ) {
4851 $ logData = array_merge ($ logData , $ this ->gatherResponseInformation ($ response ));
4952 }
@@ -129,8 +132,8 @@ private function getFieldCount(string $query): int
129132 );
130133 return $ totalFieldCount ;
131134 }
132- } catch (SyntaxError $ syntaxError ) {
133135 } catch (\Exception $ exception ) {
136+ return -1 ;
134137 }
135138 return 0 ;
136139 }
Original file line number Diff line number Diff line change @@ -204,6 +204,32 @@ public function getQueryInformationDataProvider()
204204 LoggerInterface::HTTP_RESPONSE_CODE => 200
205205 ]
206206 ],
207+ [ // bad query
208+ 'query ' => <<<QUERY
209+ {
210+ xyz()
211+ {
212+ dfsfa
213+ sku
214+ }
215+ }
216+ }
217+ QUERY ,
218+ 'headers ' => [
219+ 'response ' => [
220+ 'X-Magento-Tags ' => 'FPC '
221+ ]
222+ ],
223+ 'expectedResult ' => [
224+ LoggerInterface::HTTP_METHOD => 'POST ' ,
225+ LoggerInterface::STORE_HEADER => '' ,
226+ LoggerInterface::CURRENCY_HEADER => '' ,
227+ LoggerInterface::HAS_AUTH_HEADER => 'false ' ,
228+ LoggerInterface::IS_CACHEABLE => 'true ' ,
229+ LoggerInterface::REQUEST_LENGTH => '' ,
230+ LoggerInterface::HTTP_RESPONSE_CODE => 200
231+ ]
232+ ],
207233 [ // mutation with all headers
208234 'query ' => <<<QUERY
209235mutation {
You can’t perform that action at this time.
0 commit comments