11import asyncio
2+ import sys
23import warnings
3- from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union
4+ from typing import Any , AsyncGenerator , Dict , Generator , Optional , Union , overload
45
56from graphql import (
67 DocumentNode ,
2021from .utilities import parse_result as parse_result_fn
2122from .utilities import serialize_variable_values
2223
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+
2334
2435class Client :
2536 """The Client class is the main entrypoint to execute GraphQL requests
@@ -362,6 +373,34 @@ def _execute(
362373
363374 return result
364375
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+
365404 def execute (
366405 self ,
367406 document : DocumentNode ,
@@ -525,6 +564,34 @@ async def _subscribe(
525564 finally :
526565 await inner_generator .aclose ()
527566
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+
528595 async def subscribe (
529596 self ,
530597 document : DocumentNode ,
@@ -535,7 +602,9 @@ async def subscribe(
535602 parse_result : Optional [bool ] = None ,
536603 get_execution_result : bool = False ,
537604 ** kwargs ,
538- ) -> AsyncGenerator [Union [Dict [str , Any ], ExecutionResult ], None ]:
605+ ) -> Union [
606+ AsyncGenerator [Dict [str , Any ], None ], AsyncGenerator [ExecutionResult , None ]
607+ ]:
539608 """Coroutine to subscribe asynchronously to the provided document AST
540609 asynchronously using the async transport.
541610
@@ -653,6 +722,34 @@ async def _execute(
653722
654723 return result
655724
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+
656753 async def execute (
657754 self ,
658755 document : DocumentNode ,
0 commit comments