@@ -944,37 +944,49 @@ def when_no_runtime_value_is_provided_to_a_non_null_argument():
944944 )
945945
946946 def describe_get_variable_values_limit_maximum_number_of_coercion_errors ():
947- def when_values_are_invalid ():
948- doc = parse (
949- """
950- query ($input: [String!]) {
951- listNN(input: $input)
952- }
953- """
947+ doc = parse (
948+ """
949+ query ($input: [String!]) {
950+ listNN(input: $input)
951+ }
952+ """
953+ )
954+
955+ operation = doc .definitions [0 ]
956+ assert isinstance (operation , OperationDefinitionNode )
957+ variable_definitions = operation .variable_definitions
958+ assert variable_definitions is not None
959+
960+ input_value = {"input" : [0 , 1 , 2 ]}
961+
962+ def _invalid_value_error (value , index ):
963+ return {
964+ "message" : "Variable '$input' got invalid value"
965+ f" { value } at 'input[{ index } ]';"
966+ " Expected type String."
967+ f" String cannot represent a non string value: { value } " ,
968+ "locations" : [(2 , 20 )],
969+ }
970+
971+ def when_max_errors_is_equal_to_number_of_errors ():
972+ result = get_variable_values (
973+ schema , variable_definitions , input_value , max_errors = 3
954974 )
955- operation = doc .definitions [0 ]
956- assert isinstance (operation , OperationDefinitionNode )
957975
976+ assert result == [
977+ _invalid_value_error (0 , 0 ),
978+ _invalid_value_error (1 , 1 ),
979+ _invalid_value_error (2 , 2 ),
980+ ]
981+
982+ def when_max_errors_is_less_than_number_of_errors ():
958983 result = get_variable_values (
959- schema ,
960- operation .variable_definitions or [],
961- {"input" : [0 , 1 , 2 ]},
962- max_errors = 2 ,
984+ schema , variable_definitions , input_value , max_errors = 2
963985 )
964986
965987 assert result == [
966- {
967- "message" : "Variable '$input' got invalid value 0"
968- " at 'input[0]'; Expected type String."
969- " String cannot represent a non string value: 0" ,
970- "locations" : [(2 , 24 )],
971- },
972- {
973- "message" : "Variable '$input' got invalid value 1"
974- " at 'input[1]'; Expected type String."
975- " String cannot represent a non string value: 1" ,
976- "locations" : [(2 , 24 )],
977- },
988+ _invalid_value_error (0 , 0 ),
989+ _invalid_value_error (1 , 1 ),
978990 {
979991 "message" : "Too many errors processing variables,"
980992 " error limit reached. Execution aborted."
0 commit comments