Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ The corresponding between extra dependencies required and the GQL classes is:
+---------------------+------------------------------------------------------------------+
| requests | :ref:`RequestsHTTPTransport <requests_transport>` |
+---------------------+------------------------------------------------------------------+
| httpx | :ref:`HTTPTXTransport <httpx_transport>` |
| httpx2 or httpx | :ref:`HTTPTXTransport <httpx_transport>` |
| | |
| | :ref:`HTTPXAsyncTransport <httpx_async_transport>` |
+---------------------+------------------------------------------------------------------+
Expand Down
3 changes: 2 additions & 1 deletion docs/transports/httpx.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
HTTPXTransport
==============

The HTTPXTransport is a sync transport using the `httpx`_ library
The HTTPXTransport is a sync transport using the `httpx2`_ or `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
.. _httpx2: https://httpx2.pydantic.dev
3 changes: 2 additions & 1 deletion docs/transports/httpx_async.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
HTTPXAsyncTransport
===================

This transport uses the `httpx`_ library and allows you to send GraphQL queries using the HTTP protocol.
This transport uses the `httpx2`_ or `httpx`_ library and allows you to send GraphQL queries using the HTTP protocol.

Reference: :class:`gql.transport.httpx.HTTPXAsyncTransport`

Expand Down Expand Up @@ -37,3 +37,4 @@ You can manually set the cookies which will be sent with each connection:
transport = HTTPXAsyncTransport(url=url, cookies={"cookie1": "val1"})

.. _httpx: https://www.python-httpx.org
.. _httpx2: https://httpx2.pydantic.dev
6 changes: 5 additions & 1 deletion gql/transport/httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@
Union,
)

import httpx
try:
import httpx2 as httpx
except ModuleNotFoundError: # pragma: no cover
import httpx # type: ignore[no-redef]

from graphql import ExecutionResult

from ..graphql_request import GraphQLRequest
Expand Down
7 changes: 6 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@
"httpx>=0.27.0,<1",
]

install_httpx2_requires = [
"httpx2>=2.0.0,<3",
]

install_websockets_requires = [
"websockets>=14.2,<16",
]
Expand All @@ -65,7 +69,7 @@
]

install_all_requires = (
install_aiohttp_requires + install_requests_requires + install_httpx_requires + install_websockets_requires + install_botocore_requires + install_aiofiles_requires
install_aiohttp_requires + install_requests_requires + install_httpx2_requires + install_websockets_requires + install_botocore_requires + install_aiofiles_requires
)

# Get version from __version__.py file
Expand Down Expand Up @@ -110,6 +114,7 @@
"aiohttp": install_aiohttp_requires,
"requests": install_requests_requires,
"httpx": install_httpx_requires,
"httpx2": install_httpx2_requires,
"websockets": install_websockets_requires,
"botocore": install_botocore_requires,
"aiofiles": install_aiofiles_requires,
Expand Down
11 changes: 8 additions & 3 deletions tests/test_httpx.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,19 +216,24 @@ def test_code():

query = gql(query1_str)

expected_error = "certificate verify failed: self-signed certificate"
expected_errors = [
# Linux / OpenSSL error message
"certificate verify failed: self-signed certificate",
# Windows error message
"not trusted by the trust provider",
]

with pytest.raises(TransportConnectionFailed) as exc_info:
with Client(transport=transport) as session:
session.execute(query)

assert expected_error in str(exc_info.value)
assert any(err in str(exc_info.value) for err in expected_errors)

with pytest.raises(TransportConnectionFailed) as exc_info:
with Client(transport=transport) as session:
session.execute_batch([query])

assert expected_error in str(exc_info.value)
assert any(err in str(exc_info.value) for err in expected_errors)

await run_sync_test(server, test_code)

Expand Down
17 changes: 13 additions & 4 deletions tests/test_httpx_async.py
Original file line number Diff line number Diff line change
Expand Up @@ -436,7 +436,11 @@ async def handler(request):
@pytest.mark.aiohttp
@pytest.mark.asyncio
async def test_httpx_extra_args(aiohttp_server):
import httpx
try:
import httpx2 as httpx
except ModuleNotFoundError: # pragma: no cover
import httpx # type: ignore[no-redef]

from aiohttp import web

from gql.transport.httpx import HTTPXAsyncTransport
Expand Down Expand Up @@ -1179,19 +1183,24 @@ async def handler(request):

query = gql(query1_str)

expected_error = "certificate verify failed: self-signed certificate"
expected_errors = [
# Linux / OpenSSL error message
"certificate verify failed: self-signed certificate",
# Windows error message
"not trusted by the trust provider",
]

with pytest.raises(TransportConnectionFailed) as exc_info:
async with Client(transport=transport) as session:
await session.execute(query)

assert expected_error in str(exc_info.value)
assert any(err in str(exc_info.value) for err in expected_errors)

with pytest.raises(TransportConnectionFailed) as exc_info:
async with Client(transport=transport) as session:
await session.execute_batch([query])

assert expected_error in str(exc_info.value)
assert any(err in str(exc_info.value) for err in expected_errors)


@pytest.mark.aiohttp
Expand Down
6 changes: 5 additions & 1 deletion tests/test_httpx_batch.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,11 @@ async def handler(request):
@pytest.mark.aiohttp
@pytest.mark.asyncio
async def test_httpx_async_batch_extra_args(aiohttp_server):
import httpx
try:
import httpx2 as httpx
except ModuleNotFoundError: # pragma: no cover
import httpx # type: ignore[no-redef]

from aiohttp import web

from gql.transport.httpx import HTTPXAsyncTransport
Expand Down
Loading