File tree Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Expand file tree Collapse file tree 3 files changed +39
-5
lines changed Original file line number Diff line number Diff line change 1+ import trio
2+
3+ from gql import Client , gql
4+ from gql .transport .httpx import HTTPXAsyncTransport
5+
6+
7+ async def main ():
8+
9+ transport = HTTPXAsyncTransport (url = "https://countries.trevorblades.com/graphql" )
10+
11+ # Using `async with` on the client will start a connection on the transport
12+ # and provide a `session` variable to execute queries on this connection
13+ async with Client (
14+ transport = transport ,
15+ fetch_schema_from_transport = True ,
16+ ) as session :
17+
18+ # Execute single query
19+ query = gql (
20+ """
21+ query getContinents {
22+ continents {
23+ code
24+ name
25+ }
26+ }
27+ """
28+ )
29+
30+ result = await session .execute (query )
31+ print (result )
32+
33+
34+ trio .run (main )
Original file line number Diff line number Diff line change 2222)
2323
2424import backoff
25+ from anyio import fail_after
2526from graphql import (
2627 DocumentNode ,
2728 ExecutionResult ,
@@ -1532,15 +1533,13 @@ async def _execute(
15321533 )
15331534
15341535 # Execute the query with the transport with a timeout
1535- result = await asyncio . wait_for (
1536- self .transport .execute (
1536+ with fail_after ( self . client . execute_timeout ):
1537+ result = await self .transport .execute (
15371538 document ,
15381539 variable_values = variable_values ,
15391540 operation_name = operation_name ,
15401541 ** kwargs ,
1541- ),
1542- self .client .execute_timeout ,
1543- )
1542+ )
15441543
15451544 # Unserialize the result if requested
15461545 if self .client .schema :
Original file line number Diff line number Diff line change 66 "graphql-core>=3.3.0a3,<3.4" ,
77 "yarl>=1.6,<2.0" ,
88 "backoff>=1.11.1,<3.0" ,
9+ "anyio>=3.0,<5" ,
910]
1011
1112console_scripts = [
You can’t perform that action at this time.
0 commit comments