8000 get_variable_values: improve coverage of 'max_errors' · graphql-python/graphql-core@8f0eae6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 8f0eae6

Browse files
committed
get_variable_values: improve coverage of 'max_errors'
Replicates graphql/graphql-js@ebcdfd2
1 parent fc1b1f9 commit 8f0eae6

File tree

2 files changed

+38
-26
lines changed

2 files changed

+38
-26
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current version 3.0.0a2 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.4.2.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1925 unit tests.
19+
of currently 1932 unit tests.
2020

2121

2222
## Documentation

tests/execution/test_variables.py

Lines changed: 37 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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 106CB
)
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

Comments
 (0)
0