File tree 4 files changed +40
-0
lines changed
4 files changed +40
-0
lines changed Original file line number Diff line number Diff line change 5
5
:maxdepth: 2
6
6
7
7
async_advanced_usage
8
+ logging
8
9
local_schema
9
10
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(
183
183
if variable_values :
184
184
payload ["variables" ] = variable_values
185
185
186
+ if log .isEnabledFor (logging .INFO ):
187
+ log .info (">>> %s" , json .dumps (payload ))
188
+
186
189
post_args = {"json" : payload }
187
190
188
191
# Pass post_args to aiohttp post method
@@ -195,6 +198,10 @@ async def execute(
195
198
async with self .session .post (self .url , ssl = self .ssl , ** post_args ) as resp :
196
199
try :
197
200
result = await resp .json ()
201
+
202
+ if log .isEnabledFor (logging .INFO ):
203
+ result_text = await resp .text ()
204
+ log .info ("<<< %s" , result_text )
198
205
except Exception :
199
206
# We raise a TransportServerError if the status code is 400 or higher
200
207
# We raise a TransportProtocolError in the other cases
Original file line number Diff line number Diff line change
1
+ import json
2
+ import logging
1
3
from typing import Any , Dict , Optional , Union
2
4
3
5
import requests
15
17
TransportServerError ,
16
18
)
17
19
20
+ log = logging .getLogger (__name__ )
21
+
18
22
19
23
class RequestsHTTPTransport (Transport ):
20
24
""":ref:`Sync Transport <sync_transports>` used to execute GraphQL queries
@@ -135,6 +139,10 @@ def execute( # type: ignore
135
139
data_key : payload ,
136
140
}
137
141
142
+ # Log the payload
143
+ if log .isEnabledFor (logging .INFO ):
144
+ log .info (">>> %s" , json .dumps (payload ))
145
+
138
146
# Pass kwargs to requests post method
139
147
post_args .update (self .kwargs )
140
148
@@ -144,6 +152,9 @@ def execute( # type: ignore
144
152
)
145
153
try :
146
154
result = response .json ()
155
+
156
+ if log .isEnabledFor (logging .INFO ):
157
+ log .info ("<<< %s" , response .text )
147
158
except Exception :
148
159
# We raise a TransportServerError if the status code is 400 or higher
149
160
# We raise a TransportProtocolError in the other cases
You can’t perform that action at this time.
0 commit comments