-
Notifications
You must be signed in to change notification settings - Fork 185
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
2,836 additions
and
6 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import asyncio | ||
|
||
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) | ||
|
||
|
||
asyncio.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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from gql import Client, gql | ||
from gql.transport.httpx import HTTPXTransport | ||
|
||
transport = HTTPXTransport(url="https://countries.trevorblades.com/") | ||
|
||
client = Client(transport=transport, fetch_schema_from_transport=True) | ||
|
||
query = gql( | ||
""" | ||
query getContinents { | ||
continents { | ||
code | ||
name | ||
} | ||
} | ||
""" | ||
) | ||
|
||
result = client.execute(query) | ||
print(result) |
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
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,7 @@ | ||
gql.transport.httpx | ||
=================== | ||
|
||
.. currentmodule:: gql.transport.httpx | ||
|
||
.. automodule:: gql.transport.httpx | ||
:member-order: bysource |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. _httpx_transport: | ||
|
||
HTTPXTransport | ||
============== | ||
|
||
The HTTPXTransport is a sync transport using the `httpx`_ library | ||
and allows you to send GraphQL queries using the HTTP protocol. | ||
|
||
Reference: :class:`gql.transport.httpx.HTTPXTransport` | ||
|
||
.. literalinclude:: ../code_examples/httpx_sync.py | ||
|
||
.. _httpx: https://www.python-httpx.org |
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,39 @@ | ||
.. _httpx_async_transport: | ||
|
||
HTTPXAsyncTransport | ||
=================== | ||
|
||
This transport uses the `httpx`_ library and allows you to send GraphQL queries using the HTTP protocol. | ||
|
||
Reference: :class:`gql.transport.httpx.HTTPXAsyncTransport` | ||
|
||
.. note:: | ||
|
||
GraphQL subscriptions are not supported on the HTTP transport. | ||
For subscriptions you should use the :ref:`websockets transport <websockets_transport>`. | ||
|
||
.. literalinclude:: ../code_examples/httpx_async.py | ||
|
||
Authentication | ||
-------------- | ||
|
||
There are multiple ways to authenticate depending on the server configuration. | ||
|
||
1. Using HTTP Headers | ||
|
||
.. code-block:: python | ||
transport = HTTPXAsyncTransport( | ||
url='https://SERVER_URL:SERVER_PORT/graphql', | ||
headers={'Authorization': 'token'} | ||
) | ||
2. Using HTTP Cookies | ||
|
||
You can manually set the cookies which will be sent with each connection: | ||
|
||
.. code-block:: python | ||
transport = HTTPXAsyncTransport(url=url, cookies={"cookie1": "val1"}) | ||
.. _httpx: https://www.python-httpx.org |
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 |
---|---|---|
|
@@ -10,3 +10,4 @@ They cannot be used asynchronously. | |
:maxdepth: 1 | ||
|
||
requests | ||
httpx |
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
Oops, something went wrong.