55use Esign \LaravelShopify \Auth \TokenRefreshService ;
66use Esign \LaravelShopify \Exceptions \TokenRefreshRequiredException ;
77use Esign \LaravelShopify \GraphQL \Concerns \HandlesGraphQLErrors ;
8- use Esign \LaravelShopify \GraphQL \Concerns \LogsGraphQLOperations ;
98use Esign \LaravelShopify \GraphQL \Contracts \Mutation ;
109use Esign \LaravelShopify \GraphQL \Contracts \PaginatedQuery ;
1110use Esign \LaravelShopify \GraphQL \Contracts \Query ;
1211use Esign \LaravelShopify \Models \Shop ;
13- use Illuminate \Support \Facades \Log ;
12+ use Esign \LaravelShopify \Support \LogCategory ;
13+ use Esign \LaravelShopify \Support \ShopifyLogger ;
1414use Shopify \App \ShopifyApp ;
1515use Shopify \App \Types \GQLResult ;
1616
1717class Client
1818{
19- use HandlesGraphQLErrors, LogsGraphQLOperations ;
19+ use HandlesGraphQLErrors;
2020
2121 protected ShopifyApp $ shopifyApp ;
2222
@@ -34,7 +34,7 @@ public function __construct(
3434 */
3535 public function query (Query $ query ): mixed
3636 {
37- $ this ->logOperation ('query ' , $ query ->query (), $ query ->variables ());
37+ $ this ->logOperation ('query ' , LogCategory::GraphqlQueries, $ query ->query (), $ query ->variables ());
3838
3939 $ response = $ this ->executeGraphQL ($ query ->query (), $ query ->variables ());
4040
@@ -46,7 +46,7 @@ public function query(Query $query): mixed
4646 */
4747 public function mutation (Mutation $ mutation ): mixed
4848 {
49- $ this ->logOperation ('mutation ' , $ mutation ->query (), $ mutation ->variables ());
49+ $ this ->logOperation ('mutation ' , LogCategory::GraphqlMutations, $ mutation ->query (), $ mutation ->variables ());
5050
5151 $ response = $ this ->executeGraphQL ($ mutation ->query (), $ mutation ->variables ());
5252
@@ -61,7 +61,7 @@ public function queryPaginated(PaginatedQuery $query): array
6161 $ results = [];
6262
6363 do {
64- $ this ->logOperation ('query ' , $ query ->query (), $ query ->variables ());
64+ $ this ->logOperation ('query ' , LogCategory::GraphqlQueries, $ query ->query (), $ query ->variables ());
6565
6666 $ response = $ this ->executeGraphQL ($ query ->query (), $ query ->variables ());
6767
@@ -86,14 +86,14 @@ protected function executeGraphQL(string $query, array $variables = []): GQLResu
8686
8787 // Check for authentication errors (retriable)
8888 if (! $ result ->ok && $ this ->isAuthenticationError ($ result )) {
89- Log:: info ('GraphQL authentication error detected, attempting token refresh ' , [
89+ ShopifyLogger:: log (LogCategory::TokenLifecycle)-> info ('GraphQL authentication error detected, attempting token refresh ' , [
9090 'shop ' => $ this ->shop ->domain ,
9191 'error_code ' => $ result ->log ->code ,
9292 'error_detail ' => $ result ->log ->detail ,
9393 ]);
9494
9595 if ($ this ->attemptTokenRefresh ()) {
96- Log:: info ('Token refresh successful, retrying GraphQL request ' , [
96+ ShopifyLogger:: log (LogCategory::TokenLifecycle)-> info ('Token refresh successful, retrying GraphQL request ' , [
9797 'shop ' => $ this ->shop ->domain ,
9898 ]);
9999
@@ -153,7 +153,7 @@ protected function attemptTokenRefresh(): bool
153153
154154 return false ;
155155 } catch (\Exception $ e ) {
156- Log:: error ('Token refresh attempt failed ' , [
156+ ShopifyLogger:: log (LogCategory::TokenLifecycle)-> error ('Token refresh attempt failed ' , [
157157 'shop ' => $ this ->shop ->domain ,
158158 'error ' => $ e ->getMessage (),
159159 ]);
@@ -191,4 +191,16 @@ protected function isAuthenticationError(GQLResult $result): bool
191191
192192 return false ;
193193 }
194+
195+ /**
196+ * Log a GraphQL operation if its category flag is enabled.
197+ */
198+ protected function logOperation (string $ type , LogCategory $ category , string $ query , array $ variables ): void
199+ {
200+ ShopifyLogger::log ($ category )->info ("GraphQL {$ type } executed " , [
201+ 'shop ' => $ this ->shop ->domain ,
202+ 'query ' => $ query ,
203+ 'variables ' => $ variables ,
204+ ]);
205+ }
194206}
0 commit comments