1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
from functools import partial
from graphql.validation import UniqueInputFieldNamesRule
from .harness import assert_validation_errors
assert_errors = partial(assert_validation_errors, UniqueInputFieldNamesRule)
assert_valid = partial(assert_errors, errors=[])
def describe_validate_unique_input_field_names():
def input_object_with_fields():
assert_valid(
"""
{
field(arg: { f: true })
}
"""
)
def same_input_object_within_two_args():
assert_valid(
"""
{
field(arg1: { f: true }, arg2: { f: true })
}
"""
)
def multiple_input_object_fields():
assert_valid(
"""
{
field(arg: { f1: "value", f2: "value", f3: "value" })
}
"""
)
def allows_for_nested_input_objects_with_similar_fields():
assert_valid(
"""
{
field(arg: {
deep: {
deep: {
id: 1
}
id: 1
}
id: 1
})
}
"""
)
def duplicate_input_object_fields():
assert_errors(
"""
{
field(arg: { f1: "value", f1: "value" })
}
""",
[
{
"message": "There can be only one input field named 'f1'.",
"locations": [(3, 28), (3, 41)],
},
],
)
def many_duplicate_input_object_fields():
assert_errors(
"""
{
field(arg: { f1: "value", f1: "value", f1: "value" })
}
""",
[
{
"message": "There can be only one input field named 'f1'.",
"locations": [(3, 28), (3, 41)],
},
{
"message": "There can be only one input field named 'f1'.",
"locations": [(3, 28), (3, 54)],
},
],
)
def nested_duplicate_input_object_fields():
assert_errors(
"""
{
field(arg: { f1: {f2: "value", f2: "value" }})
}
""",
[
{
"message": "There can be only one input field named 'f2'.",
"locations": [(3, 33), (3, 46)],
},
],
)
|