Skip to content

Commit

Permalink
Use httpx with gql-cli if aiohttp is not available on auto (#528)
Browse files Browse the repository at this point in the history
  • Loading branch information
leszekhanusz authored Jan 30, 2025
1 parent ed63734 commit b066e89
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion gql/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,23 @@ def autodetect_transport(url: URL) -> str:

else:
assert url.scheme in ["http", "https"]
transport_name = "aiohttp"

try:
from gql.transport.aiohttp import AIOHTTPTransport # noqa: F401

transport_name = "aiohttp"
except ModuleNotFoundError: # pragma: no cover
try:
from gql.transport.httpx import HTTPXAsyncTransport # noqa: F401

transport_name = "httpx"
except ModuleNotFoundError:
raise ModuleNotFoundError(
"\n\nNo suitable dependencies has been found for an http(s) backend"
" (aiohttp or httpx).\n\n"
"Please check the install documentation at:\n"
"https://gql.readthedocs.io/en/stable/intro.html#installation\n"
)

return transport_name

Expand Down Expand Up @@ -462,6 +478,9 @@ async def main(args: Namespace) -> int:
except ValueError as e:
print(f"Error: {e}", file=sys.stderr)
return 1
except ModuleNotFoundError as e: # pragma: no cover
print(f"Error: {e}", file=sys.stderr)
return 2

# By default, the exit_code is 0 (everything is ok)
exit_code = 0
Expand Down

0 comments on commit b066e89

Please sign in to comment.