From b7c58656ae49645aecdf848e7906fd00ee8fd050 Mon Sep 17 00:00:00 2001 From: "Malte S. Stretz" Date: Wed, 11 Dec 2024 15:04:44 +0100 Subject: [PATCH] Wire httpx transport in gql-cli (#513) --- gql/cli.py | 6 ++++++ tests/test_cli.py | 16 ++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/gql/cli.py b/gql/cli.py index a7d129e2..06781c2b 100644 --- a/gql/cli.py +++ b/gql/cli.py @@ -157,6 +157,7 @@ def get_parser(with_examples: bool = False) -> ArgumentParser: choices=[ "auto", "aiohttp", + "httpx", "phoenix", "websockets", "aiohttp_websockets", @@ -330,6 +331,11 @@ def get_transport(args: Namespace) -> Optional[AsyncTransport]: return AIOHTTPTransport(url=args.server, **transport_args) + elif transport_name == "httpx": + from gql.transport.httpx import HTTPXAsyncTransport + + return HTTPXAsyncTransport(url=args.server, **transport_args) + elif transport_name == "phoenix": from gql.transport.phoenix_channel_websockets import ( PhoenixChannelWebsocketsTransport, diff --git a/tests/test_cli.py b/tests/test_cli.py index 88d1f533..dccfcb5a 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -190,6 +190,22 @@ def test_cli_get_transport_aiohttp(parser, url): assert isinstance(transport, AIOHTTPTransport) +@pytest.mark.httpx +@pytest.mark.parametrize( + "url", + ["http://your_server.com", "https://your_server.com"], +) +def test_cli_get_transport_httpx(parser, url): + + from gql.transport.httpx import HTTPXAsyncTransport + + args = parser.parse_args([url, "--transport", "httpx"]) + + transport = get_transport(args) + + assert isinstance(transport, HTTPXAsyncTransport) + + @pytest.mark.websockets @pytest.mark.parametrize( "url",