File tree Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Expand file tree Collapse file tree 2 files changed +48
-1
lines changed Original file line number Diff line number Diff line change 4646"""
4747
4848
49+ def positive_int_or_none (value_str : str ) -> Optional [int ]:
50+ """Convert a string argument value into either an int or None.
51+
52+ Raise a ValueError if the argument is negative or a string which is not "none"
53+ """
54+ try :
55+ value_int = int (value_str )
56+ except ValueError :
57+ if value_str .lower () == "none" :
58+ return None
59+ else :
60+ raise
61+
62+ if value_int < 0 :
63+ raise ValueError
64+
65+ return value_int
66+
67+
4968def get_parser (with_examples : bool = False ) -> ArgumentParser :
5069 """Provides an ArgumentParser for the gql-cli script.
5170
@@ -103,6 +122,13 @@ def get_parser(with_examples: bool = False) -> ArgumentParser:
103122 action = "store_true" ,
104123 dest = "print_schema" ,
105124 )
125+ parser .add_argument (
126+ "--execute-timeout" ,
127+ help = "set the execute_timeout argument of the Client (default: 10)" ,
128+ type = positive_int_or_none ,
129+ default = 10 ,
130+ dest = "execute_timeout" ,
131+ )
106132 parser .add_argument (
107133 "--transport" ,
108134 default = "auto" ,
@@ -367,7 +393,9 @@ async def main(args: Namespace) -> int:
367393
368394 # Connect to the backend and provide a session
369395 async with Client (
370- transport = transport , fetch_schema_from_transport = args .print_schema
396+ transport = transport ,
397+ fetch_schema_from_transport = args .print_schema ,
398+ execute_timeout = args .execute_timeout ,
371399 ) as session :
372400
373401 if args .print_schema :
Original file line number Diff line number Diff line change @@ -73,6 +73,25 @@ def test_cli_parser(parser):
7373 )
7474 assert args .operation_name == "my_operation"
7575
76+ # Check execute_timeout
77+ # gql-cli https://your_server.com --execute-timeout 1
78+ args = parser .parse_args (["https://your_server.com" , "--execute-timeout" , "1" ])
79+ assert args .execute_timeout == 1
80+
81+ # gql-cli https://your_server.com --execute-timeout=none
82+ args = parser .parse_args (["https://your_server.com" , "--execute-timeout" , "none" ])
83+ assert args .execute_timeout is None
84+
85+ # gql-cli https://your_server.com --execute-timeout=-1
86+ with pytest .raises (SystemExit ):
87+ args = parser .parse_args (["https://your_server.com" , "--execute-timeout" , "-1" ])
88+
89+ # gql-cli https://your_server.com --execute-timeout=invalid
90+ with pytest .raises (SystemExit ):
91+ args = parser .parse_args (
92+ ["https://your_server.com" , "--execute-timeout" , "invalid" ]
93+ )
94+
7695
7796def test_cli_parse_headers (parser ):
7897
You can’t perform that action at this time.
0 commit comments