diff --git a/gql/cli.py b/gql/cli.py index 27a562b2..0b2f2e25 100644 --- a/gql/cli.py +++ b/gql/cli.py @@ -73,6 +73,9 @@ def get_parser(with_examples: bool = False) -> ArgumentParser: parser.add_argument( "-H", "--headers", nargs="*", help="http headers in the form key:value" ) + parser.add_argument( + "--timeout", type=int, default=None, help="Timeout in seconds for the request." + ) parser.add_argument("--version", action="version", version=f"v{__version__}") group = parser.add_mutually_exclusive_group() group.add_argument( @@ -367,7 +370,9 @@ async def main(args: Namespace) -> int: # Connect to the backend and provide a session async with Client( - transport=transport, fetch_schema_from_transport=args.print_schema + transport=transport, + fetch_schema_from_transport=args.print_schema, + execute_timeout=args.timeout, ) as session: if args.print_schema: diff --git a/tests/test_cli.py b/tests/test_cli.py index 9066544b..7cd0bea5 100644 --- a/tests/test_cli.py +++ b/tests/test_cli.py @@ -56,6 +56,13 @@ def test_cli_parser(parser): assert args.server == "https://your_server.com" assert args.headers == ["Authorization:Bearer blahblah"] + # Call with timeout parameter + # gql-cli https://your_server.com --timeout 60 + args = parser.parse_args(["https://your_server.com", "--timeout", "60"]) + + assert args.server == "https://your_server.com" + assert args.timeout == 60 + # Check loglevel flags # gql-cli https://your_server.com --debug args = parser.parse_args(["https://your_server.com", "--debug"])