diff --git a/gql/cli.py b/gql/cli.py index 06781c2b..91c67873 100644 --- a/gql/cli.py +++ b/gql/cli.py @@ -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 @@ -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