@@ -57,17 +57,17 @@ pip install "gql[all]"
57
57
58
58
## Usage
59
59
60
- ### Basic usage
60
+ ### Sync usage
61
61
62
62
``` python
63
- from gql import gql, Client
63
+ from gql import Client, gql
64
64
from gql.transport.aiohttp import AIOHTTPTransport
65
65
66
66
# Select your transport with a defined url endpoint
67
67
transport = AIOHTTPTransport(url = " https://countries.trevorblades.com/" )
68
68
69
69
# Create a GraphQL client using the defined transport
70
- client = Client(transport = transport, fetch_schema_from_transport = True )
70
+ client = Client(transport = transport)
71
71
72
72
# Provide a GraphQL query
73
73
query = gql(
@@ -97,6 +97,47 @@ $ python basic_example.py
97
97
> python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you. In that case you
98
98
> should use instead the [ async usage example] ( https://gql.readthedocs.io/en/latest/async/async_usage.html#async-usage ) .
99
99
100
+ ### Async usage
101
+
102
+ ``` python
103
+ import asyncio
104
+
105
+ from gql import Client, gql
106
+ from gql.transport.aiohttp import AIOHTTPTransport
107
+
108
+
109
+ async def main ():
110
+
111
+ # Select your transport with a defined url endpoint
112
+ transport = AIOHTTPTransport(url = " https://countries.trevorblades.com/graphql" )
113
+
114
+ # Create a GraphQL client using the defined transport
115
+ client = Client(transport = transport)
116
+
117
+ # Provide a GraphQL query
118
+ query = gql(
119
+ """
120
+ query getContinents {
121
+ continents {
122
+ code
123
+ name
124
+ }
125
+ }
126
+ """
127
+ )
128
+
129
+ # Using `async with` on the client will start a connection on the transport
130
+ # and provide a `session` variable to execute queries on this connection
131
+ async with client as session:
132
+
133
+ # Execute the query
134
+ result = await session.execute(query)
135
+ print (result)
136
+
137
+
138
+ asyncio.run(main())
139
+ ```
140
+
100
141
## Contributing
101
142
See [ CONTRIBUTING.md] ( CONTRIBUTING.md )
102
143
0 commit comments