@@ -155,6 +155,7 @@ def _parse_and_validate(
155
155
allowed_operation_types : Optional [Set [OperationType ]],
156
156
validation_rules : Optional [tuple [type [ASTValidationRule ], ...]] = None ,
157
157
operation_name : Optional [str ] = None ,
158
+ validate_document : Optional [bool ] = None ,
158
159
# extensions_runner: SchemaExtensionsRunner
159
160
) -> DocumentNode :
160
161
if allowed_operation_types is None :
@@ -171,8 +172,14 @@ def _parse_and_validate(
171
172
try :
172
173
if isinstance (query , str ):
173
174
document_node = parse (query )
175
+ if validate_document is None :
176
+ # Validate the document by default for string queries
177
+ validate_document = True
174
178
else :
175
179
document_node = query
180
+ if validate_document is None :
181
+ # Don't validate the document by default for DocumentNode queries
182
+ validate_document = False
176
183
except GraphQLError as e :
177
184
raise GraphQLValidationError ([e ]) from e
178
185
@@ -211,6 +218,7 @@ async def execute(
211
218
custom_context_kwargs : Optional [dict [str , Any ]] = None ,
212
219
execution_context_class : type [ExecutionContext ] | None = None ,
213
220
validation_rules : Optional [tuple [type [ASTValidationRule ], ...]] = None ,
221
+ validate_document : Optional [bool ] = None ,
214
222
) -> ExecutionResult :
215
223
if allowed_operation_types is None :
216
224
allowed_operation_types = DEFAULT_ALLOWED_OPERATION_TYPES
@@ -234,6 +242,7 @@ async def execute(
234
242
allowed_operation_types ,
235
243
validation_rules ,
236
244
operation_name ,
245
+ validate_document ,
237
246
)
238
247
239
248
# async with extensions_runner.executing():
@@ -274,6 +283,7 @@ def execute_sync(
274
283
custom_context_kwargs : Optional [dict [str , Any ]] = None ,
275
284
execution_context_class : type [ExecutionContext ] | None = None ,
276
285
validation_rules : Optional [tuple [type [ASTValidationRule ], ...]] = None ,
286
+ validate_document : Optional [bool ] = None ,
277
287
) -> ExecutionResult :
278
288
if custom_context_kwargs is None :
279
289
custom_context_kwargs = {}
@@ -296,6 +306,7 @@ def execute_sync(
296
306
allowed_operation_types ,
297
307
validation_rules ,
298
308
operation_name ,
309
+ validate_document ,
299
310
)
300
311
301
312
# with extensions_runner.executing():
@@ -344,6 +355,7 @@ async def subscribe(
344
355
execution_context_class : Optional [type [ExecutionContext ]] = None ,
345
356
operation_extensions : Optional [dict [str , Any ]] = None ,
346
357
validation_rules : Optional [tuple [type [ASTValidationRule ], ...]] = None ,
358
+ validate_document : Optional [bool ] = None ,
347
359
) -> AsyncGenerator [ExecutionResult , None ]:
348
360
allowed_operation_types = {
349
361
OperationType .SUBSCRIPTION ,
@@ -354,6 +366,7 @@ async def subscribe(
354
366
allowed_operation_types ,
355
367
validation_rules ,
356
368
operation_name ,
369
+ validate_document ,
357
370
)
358
371
return _subscribe_generator (
359
372
schema ,
0 commit comments