Skip to content

Commit 3b5382d

Browse files
authored
Merge branch 'master' into fix_graphql_core_3_2_0_compatibility
2 parents bc53e73 + 5440c6c commit 3b5382d

File tree

2 files changed

+104
-2
lines changed

2 files changed

+104
-2
lines changed

gql/client.py

Lines changed: 99 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import asyncio
2+
import sys
23
import warnings
3-
from typing import Any, AsyncGenerator, Dict, Generator, Optional, Union
4+
from typing import Any, AsyncGenerator, Dict, Generator, Optional, Union, overload
45

56
from graphql import (
67
DocumentNode,
@@ -20,6 +21,16 @@
2021
from .utilities import parse_result as parse_result_fn
2122
from .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

2435
class 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,

tests/test_client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ def test_no_schema_exception():
8585
)
8686

8787

88+
@pytest.mark.online
8889
@pytest.mark.requests
8990
def test_execute_result_error():
9091

@@ -111,6 +112,7 @@ def test_execute_result_error():
111112
assert 'Cannot query field "id" on type "Continent".' in str(exc_info.value)
112113

113114

115+
@pytest.mark.online
114116
@pytest.mark.requests
115117
def test_http_transport_raise_for_status_error(http_transport_query):
116118
from gql.transport.requests import RequestsHTTPTransport
@@ -127,6 +129,7 @@ def test_http_transport_raise_for_status_error(http_transport_query):
127129
assert "400 Client Error: Bad Request for url" in str(exc_info.value)
128130

129131

132+
@pytest.mark.online
130133
@pytest.mark.requests
131134
def test_http_transport_verify_error(http_transport_query):
132135
from gql.transport.requests import RequestsHTTPTransport
@@ -142,6 +145,7 @@ def test_http_transport_verify_error(http_transport_query):
142145
assert "Unverified HTTPS request is being made to host" in str(record[0].message)
143146

144147

148+
@pytest.mark.online
145149
@pytest.mark.requests
146150
def test_http_transport_specify_method_valid(http_transport_query):
147151
from gql.transport.requests import RequestsHTTPTransport
@@ -155,6 +159,7 @@ def test_http_transport_specify_method_valid(http_transport_query):
155159
assert result is not None
156160

157161

162+
@pytest.mark.online
158163
@pytest.mark.requests
159164
def test_http_transport_specify_method_invalid(http_transport_query):
160165
from gql.transport.requests import RequestsHTTPTransport

0 commit comments

Comments
 (0)