Skip to content

Commit 8fc378d

Browse files
authored
DOC add note to warn about running basic example with an asyncio event loop running (#116)
Small fixes for the assertion messages
1 parent efb96ea commit 8fc378d

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ result = client.execute(query)
6363
print(result)
6464
```
6565

66+
> **WARNING**: Please note that this basic example won't work if you have an asyncio event loop running. In some
67+
> python environments (as with Jupyter which uses IPython) an asyncio event loop is created for you. In that case you
68+
> should use instead the example in the [AIOHTTPTransport](#HTTP-async-transport) section.
69+
6670
### Local schema validation
6771

6872
It is possible to validate a query locally either using a provided schema or by using

gql/client.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,8 @@ def execute(self, document: DocumentNode, *args, **kwargs) -> Dict:
113113
loop = asyncio.get_event_loop()
114114

115115
assert not loop.is_running(), (
116-
"Cannot run client.execute if an asyncio loop is running."
117-
" Use execute_async instead."
116+
"Cannot run client.execute(query) if an asyncio loop is running."
117+
" Use 'await client.execute_async(query)' instead."
118118
)
119119

120120
data: Dict[Any, Any] = loop.run_until_complete(
@@ -151,8 +151,8 @@ def subscribe(
151151
loop = asyncio.get_event_loop()
152152

153153
assert not loop.is_running(), (
154-
"Cannot run client.subscribe if an asyncio loop is running."
155-
" Use subscribe_async instead."
154+
"Cannot run client.subscribe(query) if an asyncio loop is running."
155+
" Use 'await client.subscribe_async(query)' instead."
156156
)
157157

158158
try:
@@ -199,9 +199,10 @@ async def __aexit__(self, exc_type, exc, tb):
199199

200200
def __enter__(self):
201201

202-
assert not isinstance(
203-
self.transport, AsyncTransport
204-
), "Only a sync transport can be use. Use 'async with Client(...)' instead"
202+
assert not isinstance(self.transport, AsyncTransport), (
203+
"Only a sync transport can be used."
204+
" Use 'async with Client(...) as session:' instead"
205+
)
205206

206207
self.transport.connect()
207208

0 commit comments

Comments
 (0)