@@ -56,7 +56,7 @@ def __init__(
56
56
:param fetch_schema_from_transport: Boolean to indicate that if we want to fetch
57
57
the schema from the transport using an introspection query
58
58
:param execute_timeout: The maximum time in seconds for the execution of a
59
- request before a TimeoutError is raised
59
+ request before a TimeoutError is raised. Only used for async transports.
60
60
"""
61
61
assert not (
62
62
type_def and introspection
@@ -103,13 +103,9 @@ def __init__(
103
103
# On async transports, we fetch the schema before executing the first query
104
104
self .fetch_schema_from_transport : bool = fetch_schema_from_transport
105
105
106
- # Enforced timeout of the execute function
106
+ # Enforced timeout of the execute function (only for async transports)
107
107
self .execute_timeout = execute_timeout
108
108
109
- if isinstance (transport , Transport ) and fetch_schema_from_transport :
110
- with self as session :
111
- session .fetch_schema ()
112
-
113
109
def validate (self , document : DocumentNode ):
114
110
""":meta private:"""
115
111
assert (
@@ -249,6 +245,10 @@ async def __aenter__(self):
249
245
if not hasattr (self , "session" ):
250
246
self .session = AsyncClientSession (client = self )
251
247
248
+ # Get schema from transport if needed
249
+ if self .fetch_schema_from_transport and not self .schema :
250
+ await self .session .fetch_schema ()
251
+
252
252
return self .session
253
253
254
254
async def __aexit__ (self , exc_type , exc , tb ):
@@ -267,6 +267,10 @@ def __enter__(self):
267
267
if not hasattr (self , "session" ):
268
268
self .session = SyncClientSession (client = self )
269
269
270
+ # Get schema from transport if needed
271
+ if self .fetch_schema_from_transport and not self .schema :
272
+ self .session .fetch_schema ()
273
+
270
274
return self .session
271
275
272
276
def __exit__ (self , * args ):
@@ -335,26 +339,13 @@ def __init__(self, client: Client):
335
339
""":param client: the :class:`client <gql.client.Client>` used"""
336
340
self .client = client
337
341
338
- async def fetch_and_validate (self , document : DocumentNode ):
339
- """Fetch schema from transport if needed and validate document.
340
-
341
- If no schema is present, the validation will be skipped.
342
- """
343
-
344
- # Get schema from transport if needed
345
- if self .client .fetch_schema_from_transport and not self .client .schema :
346
- await self .fetch_schema ()
347
-
348
- # Validate document
349
- if self .client .schema :
350
- self .client .validate (document )
351
-
352
342
async def _subscribe (
353
343
self , document : DocumentNode , * args , ** kwargs
354
344
) -> AsyncGenerator [ExecutionResult , None ]:
355
345
356
- # Fetch schema from transport if needed and validate document if possible
357
- await self .fetch_and_validate (document )
346
+ # Validate document
347
+ if self .client .schema :
348
+ self .client .validate (document )
358
349
359
350
# Subscribe to the transport
360
351
inner_generator : AsyncGenerator [
@@ -396,8 +387,10 @@ async def subscribe(
396
387
async def _execute (
397
388
self , document : DocumentNode , * args , ** kwargs
398
389
) -> ExecutionResult :
399
- # Fetch schema from transport if needed and validate document if possible
400
- await self .fetch_and_validate (document )
390
+
391
+ # Validate document
392
+ if self .client .schema :
393
+ self .client .validate (document )
401
394
402
395
# Execute the query with the transport with a timeout
403
396
return await asyncio .wait_for (
0 commit comments