File tree Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Expand file tree Collapse file tree 4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 55 :maxdepth: 2
66
77 async_advanced_usage
8+ logging
89 local_schema
910 dsl_module
Original file line number Diff line number Diff line change 1+ Logging
2+ =======
3+
4+ GQL use the python `logging `_ module.
5+
6+ In order to debug a problem, you can enable logging to see the messages exchanged between the client and the server.
7+ To do that, set the loglevel at **INFO ** at the beginning of your code:
8+
9+ .. code-block :: python
10+
11+ import logging
12+ logging.basicConfig(level = logging.INFO )
13+
14+ For even more logs, you can set the loglevel at **DEBUG **:
15+
16+ .. code-block :: python
17+
18+ import logging
19+ logging.basicConfig(level = logging.DEBUG )
20+
21+ .. _logging : https://docs.python.org/3/howto/logging.html
Original file line number Diff line number Diff line change @@ -183,6 +183,9 @@ async def execute(
183183 if variable_values :
184184 payload ["variables" ] = variable_values
185185
186+ if log .isEnabledFor (logging .INFO ):
187+ log .info (">>> %s" , json .dumps (payload ))
188+
186189 post_args = {"json" : payload }
187190
188191 # Pass post_args to aiohttp post method
@@ -195,6 +198,10 @@ async def execute(
195198 async with self .session .post (self .url , ssl = self .ssl , ** post_args ) as resp :
196199 try :
197200 result = await resp .json ()
201+
202+ if log .isEnabledFor (logging .INFO ):
203+ result_text = await resp .text ()
204+ log .info ("<<< %s" , result_text )
198205 except Exception :
199206 # We raise a TransportServerError if the status code is 400 or higher
200207 # We raise a TransportProtocolError in the other cases
Original file line number Diff line number Diff line change 1+ import json
2+ import logging
13from typing import Any , Dict , Optional , Union
24
35import requests
1517 TransportServerError ,
1618)
1719
20+ log = logging .getLogger (__name__ )
21+
1822
1923class RequestsHTTPTransport (Transport ):
2024 """:ref:`Sync Transport <sync_transports>` used to execute GraphQL queries
@@ -135,6 +139,10 @@ def execute( # type: ignore
135139 data_key : payload ,
136140 }
137141
142+ # Log the payload
143+ if log .isEnabledFor (logging .INFO ):
144+ log .info (">>> %s" , json .dumps (payload ))
145+
138146 # Pass kwargs to requests post method
139147 post_args .update (self .kwargs )
140148
@@ -144,6 +152,9 @@ def execute( # type: ignore
144152 )
145153 try :
146154 result = response .json ()
155+
156+ if log .isEnabledFor (logging .INFO ):
157+ log .info ("<<< %s" , response .text )
147158 except Exception :
148159 # We raise a TransportServerError if the status code is 400 or higher
149160 # We raise a TransportProtocolError in the other cases
You can’t perform that action at this time.
0 commit comments