File tree 3 files changed +39
-5
lines changed
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 22
22
)
23
23
24
24
import backoff
25
+ from anyio import fail_after
25
26
from graphql import (
26
27
DocumentNode ,
27
28
ExecutionResult ,
@@ -1532,15 +1533,13 @@ async def _execute(
1532
1533
)
1533
1534
1534
1535
# 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 (
1537
1538
document ,
1538
1539
variable_values = variable_values ,
1539
1540
operation_name = operation_name ,
1540
1541
** kwargs ,
1541
- ),
1542
- self .client .execute_timeout ,
1543
- )
1542
+ )
1544
1543
1545
1544
# Unserialize the result if requested
1546
1545
if self .client .schema :
Original file line number Diff line number Diff line change 6
6
"graphql-core>=3.3.0a3,<3.4" ,
7
7
"yarl>=1.6,<2.0" ,
8
8
"backoff>=1.11.1,<3.0" ,
9
+ "anyio>=3.0,<5" ,
9
10
]
10
11
11
12
console_scripts = [
You can’t perform that action at this time.
0 commit comments