-
Notifications
You must be signed in to change notification settings - Fork 180
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature httpx transport working with trio (#455)
- Loading branch information
1 parent
a2f327f
commit 528636a
Showing
3 changed files
with
39 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import trio | ||
|
||
from gql import Client, gql | ||
from gql.transport.httpx import HTTPXAsyncTransport | ||
|
||
|
||
async def main(): | ||
|
||
transport = HTTPXAsyncTransport(url="https://countries.trevorblades.com/graphql") | ||
|
||
# Using `async with` on the client will start a connection on the transport | ||
# and provide a `session` variable to execute queries on this connection | ||
async with Client( | ||
transport=transport, | ||
fetch_schema_from_transport=True, | ||
) as session: | ||
|
||
# Execute single query | ||
query = gql( | ||
""" | ||
query getContinents { | ||
continents { | ||
code | ||
name | ||
} | ||
} | ||
""" | ||
) | ||
|
||
result = await session.execute(query) | ||
print(result) | ||
|
||
|
||
trio.run(main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters