11<?php
22
3- namespace Graycore \GraphQlLogger \Plugin ;
3+ namespace Graycore \GraphQlLogger \Logger ;
4+
5+ use Graycore \GraphQlLogger \Model \Config ;
6+ use Magento \GraphQl \Model \Query \Logger \LoggerInterface ;
47
58use Graycore \GraphQlLogger \Api \LogRepositoryInterface ;
69use Graycore \GraphQlLogger \Api \Data \LogInterfaceFactory as LogFactory ;
7- use Graycore \GraphQlLogger \Model \Config ;
810use Magento \Framework \App \RequestInterface ;
911use Magento \Framework \Exception \NoSuchEntityException ;
10- use Magento \Framework \GraphQl \Query \QueryProcessor ;
11- use Magento \Framework \GraphQl \Schema ;
1212use Magento \Framework \Stdlib \DateTime \TimezoneInterface ;
1313
14- class LoggerPlugin
14+ class Logger implements LoggerInterface
1515{
1616 private LogRepositoryInterface $ logRepository ;
1717 private LogFactory $ logFactory ;
1818 private RequestInterface $ request ;
1919 private TimezoneInterface $ date ;
2020 private Config $ config ;
2121
22+ /**
23+ * @param Config $config
24+ */
2225 public function __construct (
2326 RequestInterface $ request ,
2427 LogRepositoryInterface $ logRepository ,
@@ -33,17 +36,16 @@ public function __construct(
3336 $ this ->config = $ config ;
3437 }
3538
36- public function afterProcess (
37- QueryProcessor $ queryProcessor ,
38- array $ value ,
39- Schema $ schema ,
40- string $ source
41- ): array {
39+ /**
40+ * @inheritdoc
41+ */
42+ public function execute (array $ queryDetails )
43+ {
4244 if (!$ this ->config ->isEnabled ()) {
43- return $ value ;
45+ return ;
4446 }
4547
46- $ hash = hash ('sha256 ' , $ source );
48+ $ hash = hash ('sha256 ' , $ queryDetails [ ' query ' ] );
4749
4850 try {
4951 $ log = $ this ->logRepository ->getByHash ($ hash );
@@ -53,10 +55,8 @@ public function afterProcess(
5355
5456 $ log ->setHash ($ hash )
5557 ->setMethod ($ this ->request ->getMethod ())
56- ->setQuery ($ source )
58+ ->setQuery ($ queryDetails [ ' query ' ] )
5759 ->setUpdated ($ this ->date ->date ()->format ('Y-m-d H:i:s ' ));
5860 $ this ->logRepository ->save ($ log );
59-
60- return $ value ;
6161 }
6262}
0 commit comments