1
1
import asyncio
2
+ import sys
2
3
import warnings
3
- from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union
4
+ from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union , overload
4
5
5
6
from graphql import (
6
7
DocumentNode ,
20
21
from .utilities import parse_result as parse_result_fn
21
22
from .utilities import serialize_variable_values
22
23
24
+ """
25
+ Load the appropriate instance of the Literal type
26
+ Note: we cannot use try: except ImportError because of the following mypy issue:
27
+ https://github.com/python/mypy/issues/8520
28
+ """
29
+ if sys .version_info [:2 ] >= (3 , 8 ):
30
+ from typing import Literal
31
+ else :
32
+ from typing_extensions import Literal # pragma: no cover
33
+
23
34
24
35
class Client :
25
36
"""The Client class is the main entrypoint to execute GraphQL requests
@@ -362,6 +373,34 @@ def _execute(
362
373
363
374
return result
364
375
376
+ @overload
377
+ def execute (
378
+ self ,
379
+ document : DocumentNode ,
380
+ * args ,
381
+ variable_values : Optional [Dict [str , Any ]] = ...,
382
+ operation_name : Optional [str ] = ...,
383
+ serialize_variables : Optional [bool ] = ...,
384
+ parse_result : Optional [bool ] = ...,
385
+ get_execution_result : Literal [False ] = ...,
386
+ ** kwargs ,
387
+ ) -> Dict [str , Any ]:
388
+ ... # pragma: no cover
389
+
390
+ @overload
391
+ def execute (
392
+ self ,
393
+ document : DocumentNode ,
394
+ * args ,
395
+ variable_values : Optional [Dict [str , Any ]] = ...,
396
+ operation_name : Optional [str ] = ...,
397
+ serialize_variables : Optional [bool ] = ...,
398
+ parse_result : Optional [bool ] = ...,
399
+ get_execution_result : Literal [True ],
400
+ ** kwargs ,
401
+ ) -> ExecutionResult :
402
+ ... # pragma: no cover
403
+
365
404
def execute (
366
405
self ,
367
406
document : DocumentNode ,
@@ -525,6 +564,34 @@ async def _subscribe(
525
564
finally :
526
565
await inner_generator .aclose ()
527
566
567
+ @overload
568
+ def subscribe (
569
+ self ,
570
+ document : DocumentNode ,
571
+ * args ,
572
+ variable_values : Optional [Dict [str , Any ]] = ...,
573
+ operation_name : Optional [str ] = ...,
574
+ serialize_variables : Optional [bool ] = ...,
575
+ parse_result : Optional [bool ] = ...,
576
+ get_execution_result : Literal [False ] = ...,
577
+ ** kwargs ,
578
+ ) -> AsyncGenerator [Dict [str , Any ], None ]:
579
+ ... # pragma: no cover
580
+
581
+ @overload
582
+ def subscribe (
583
+ self ,
584
+ document : DocumentNode ,
585
+ * args ,
586
+ variable_values : Optional [Dict [str , Any ]] = ...,
587
+ operation_name : Optional [str ] = ...,
588
+ serialize_variables : Optional [bool ] = ...,
589
+ parse_result : Optional [bool ] = ...,
590
+ get_execution_result : Literal [True ],
591
+ ** kwargs ,
592
+ ) -> AsyncGenerator [ExecutionResult , None ]:
593
+ ... # pragma: no cover
594
+
528
595
async def subscribe (
529
596
self ,
530
597
document : DocumentNode ,
@@ -535,7 +602,9 @@ async def subscribe(
535
602
parse_result : Optional [bool ] = None ,
536
603
get_execution_result : bool = False ,
537
604
** kwargs ,
538
- ) -> AsyncGenerator [Union [Dict [str , Any ], ExecutionResult ], None ]:
605
+ ) -> Union [
606
+ AsyncGenerator [Dict [str , Any ], None ], AsyncGenerator [ExecutionResult , None ]
607
+ ]:
539
608
"""Coroutine to subscribe asynchronously to the provided document AST
540
609
asynchronously using the async transport.
541
610
@@ -653,6 +722,34 @@ async def _execute(
653
722
654
723
return result
655
724
725
+ @overload
726
+ async def execute (
727
+ self ,
728
+ document : DocumentNode ,
729
+ * args ,
730
+ variable_values : Optional [Dict [str , Any ]] = ...,
731
+ operation_name : Optional [str ] = ...,
732
+ serialize_variables : Optional [bool ] = ...,
733
+ parse_result : Optional [bool ] = ...,
734
+ get_execution_result : Literal [False ] = ...,
735
+ ** kwargs ,
736
+ ) -> Dict [str , Any ]:
737
+ ... # pragma: no cover
738
+
739
+ @overload
740
+ async def execute (
741
+ self ,
742
+ document : DocumentNode ,
743
+ * args ,
744
+ variable_values : Optional [Dict [str , Any ]] = ...,
745
+ operation_name : Optional [str ] = ...,
746
+ serialize_variables : Optional [bool ] = ...,
747
+ parse_result : Optional [bool ] = ...,
748
+ get_execution_result : Literal [True ],
749
+ ** kwargs ,
750
+ ) -> ExecutionResult :
751
+ ... # pragma: no cover
752
+
656
753
async def execute (
657
754
self ,
658
755
document : DocumentNode ,
0 commit comments