@@ -367,8 +367,9 @@ def execute(
367
367
operation_name : Optional [str ] = None ,
368
368
serialize_variables : Optional [bool ] = None ,
369
369
parse_result : Optional [bool ] = None ,
370
+ get_execution_result : bool = False ,
370
371
** kwargs ,
371
- ) -> Dict :
372
+ ) -> Union [ Dict [ str , Any ], ExecutionResult ] :
372
373
"""Execute the provided document AST synchronously using
373
374
the sync transport.
374
375
@@ -382,6 +383,8 @@ def execute(
382
383
serialized. Used for custom scalars and/or enums. Default: False.
383
384
:param parse_result: Whether gql will unserialize the result.
384
385
By default use the parse_results attribute of the client.
386
+ :param get_execution_result: return the full ExecutionResult instance instead of
387
+ only the "data" field. Necessary if you want to get the "extensions" field.
385
388
386
389
The extra arguments are passed to the transport execute method."""
387
390
@@ -399,13 +402,19 @@ def execute(
399
402
# Raise an error if an error is returned in the ExecutionResult object
400
403
if result .errors :
401
404
raise TransportQueryError (
402
- str (result .errors [0 ]), errors = result .errors , data = result .data
405
+ str (result .errors [0 ]),
406
+ errors = result .errors ,
407
+ data = result .data ,
408
+ extensions = result .extensions ,
403
409
)
404
410
405
411
assert (
406
412
result .data is not None
407
413
), "Transport returned an ExecutionResult without data or errors"
408
414
415
+ if get_execution_result :
416
+ return result
417
+
409
418
return result .data
410
419
411
420
def fetch_schema (self ) -> None :
@@ -519,8 +528,9 @@ async def subscribe(
519
528
operation_name : Optional [str ] = None ,
520
529
serialize_variables : Optional [bool ] = None ,
521
530
parse_result : Optional [bool ] = None ,
531
+ get_execution_result : bool = False ,
522
532
** kwargs ,
523
- ) -> AsyncGenerator [Dict , None ]:
533
+ ) -> AsyncGenerator [Union [ Dict [ str , Any ], ExecutionResult ] , None ]:
524
534
"""Coroutine to subscribe asynchronously to the provided document AST
525
535
asynchronously using the async transport.
526
536
@@ -534,6 +544,8 @@ async def subscribe(
534
544
serialized. Used for custom scalars and/or enums. Default: False.
535
545
:param parse_result: Whether gql will unserialize the result.
536
546
By default use the parse_results attribute of the client.
547
+ :param get_execution_result: yield the full ExecutionResult instance instead of
548
+ only the "data" field. Necessary if you want to get the "extensions" field.
537
549
538
550
The extra arguments are passed to the transport subscribe method."""
539
551
@@ -554,11 +566,17 @@ async def subscribe(
554
566
# Raise an error if an error is returned in the ExecutionResult object
555
567
if result .errors :
556
568
raise TransportQueryError (
557
- str (result .errors [0 ]), errors = result .errors , data = result .data
569
+ str (result .errors [0 ]),
570
+ errors = result .errors ,
571
+ data = result .data ,
572
+ extensions = result .extensions ,
558
573
)
559
574
560
575
elif result .data is not None :
561
- yield result .data
576
+ if get_execution_result :
577
+ yield result
578
+ else :
579
+ yield result .data
562
580
finally :
563
581
await inner_generator .aclose ()
564
582
@@ -636,8 +654,9 @@ async def execute(
636
654
operation_name : Optional [str ] = None ,
637
655
serialize_variables : Optional [bool ] = None ,
638
656
parse_result : Optional [bool ] = None ,
657
+ get_execution_result : bool = False ,
639
658
** kwargs ,
640
- ) -> Dict :
659
+ ) -> Union [ Dict [ str , Any ], ExecutionResult ] :
641
660
"""Coroutine to execute the provided document AST asynchronously using
642
661
the async transport.
643
662
@@ -651,6 +670,8 @@ async def execute(
651
670
serialized. Used for custom scalars and/or enums. Default: False.
652
671
:param parse_result: Whether gql will unserialize the result.
653
672
By default use the parse_results attribute of the client.
673
+ :param get_execution_result: return the full ExecutionResult instance instead of
674
+ only the "data" field. Necessary if you want to get the "extensions" field.
654
675
655
676
The extra arguments are passed to the transport execute method."""
656
677
@@ -668,13 +689,19 @@ async def execute(
668
689
# Raise an error if an error is returned in the ExecutionResult object
669
690
if result .errors :
670
691
raise TransportQueryError (
671
- str (result .errors [0 ]), errors = result .errors , data = result .data
692
+ str (result .errors [0 ]),
693
+ errors = result .errors ,
694
+ data = result .data ,
695
+ extensions = result .extensions ,
672
696
)
673
697
674
698
assert (
675
699
result .data is not None
676
700
), "Transport returned an ExecutionResult without data or errors"
677
701
702
+ if get_execution_result :
703
+ return result
704
+
678
705
return result .data
679
706
680
707
async def fetch_schema (self ) -> None :
0 commit comments