| 1 |
from functools import partial |
| 2 |
from graphql.validation import UniqueArgumentNamesRule |
| 3 |
|
| 4 |
from .harness import assert_validation_errors |
| 5 |
|
| 6 |
assert_errors = partial(assert_validation_errors, UniqueArgumentNamesRule) |
| 7 |
|
| 8 |
assert_valid = partial(assert_errors, errors=[]) |
| 9 |
|
| 10 |
|
| 11 |
def describe_validate_unique_argument_names(): |
| 12 |
def no_arguments_on_field(): |
| 13 |
assert_valid(""" |
| 14 |
{ |
| 15 |
field |
| 16 |
} |
| 17 |
""") |
| 18 |
|
| 19 |
def no_arguments_on_directive(): |
| 20 |
assert_valid(""" |
| 21 |
{ |
| 22 |
field |
| 23 |
} |
| 24 |
""") |
| 25 |
|
| 26 |
def argument_on_field(): |
| 27 |
assert_valid(""" |
| 28 |
{ |
| 29 |
field(arg: "value") |
| 30 |
} |
| 31 |
""") |
| 32 |
|
| 33 |
def argument_on_directive(): |
| 34 |
assert_valid(""" |
| 35 |
{ |
| 36 |
field @directive(arg: "value") |
| 37 |
} |
| 38 |
""") |
| 39 |
|
| 40 |
def same_argument_on_two_fields(): |
| 41 |
assert_valid(""" |
| 42 |
{ |
| 43 |
one: field(arg: "value") |
| 44 |
two: field(arg: "value") |
| 45 |
} |
| 46 |
""") |
| 47 |
|
| 48 |
def same_argument_on_field_and_directive(): |
| 49 |
assert_valid(""" |
| 50 |
{ |
| 51 |
field(arg: "value") @directive(arg: "value") |
| 52 |
} |
| 53 |
""") |
| 54 |
|
| 55 |
def same_argument_on_two_directives(): |
| 56 |
assert_valid(""" |
| 57 |
{ |
| 58 |
field @directive1(arg: "value") @directive2(arg: "value") |
| 59 |
} |
| 60 |
""") |
| 61 |
|
| 62 |
def multiple_field_arguments(): |
| 63 |
assert_valid(""" |
| 64 |
{ |
| 65 |
field(arg1: "value", arg2: "value", arg3: "value") |
| 66 |
} |
| 67 |
""") |
| 68 |
|
| 69 |
def multiple_directive_arguments(): |
| 70 |
assert_valid(""" |
| 71 |
{ |
| 72 |
field @directive(arg1: "value", arg2: "value", arg3: "value") |
| 73 |
} |
| 74 |
""") |
| 75 |
|
| 76 |
def duplicate_field_arguments(): |
| 77 |
assert_errors( |
| 78 |
""" |
| 79 |
{ |
| 80 |
field(arg1: "value", arg1: "value") |
| 81 |
} |
| 82 |
""", |
| 83 |
[ |
| 84 |
{ |
| 85 |
"message": "There can be only one argument named 'arg1'.", |
| 86 |
"locations": [(3, 21), (3, 36)], |
| 87 |
}, |
| 88 |
], |
| 89 |
) |
| 90 |
|
| 91 |
def many_duplicate_field_arguments(): |
| 92 |
assert_errors( |
| 93 |
""" |
| 94 |
{ |
| 95 |
field(arg1: "value", arg1: "value", arg1: "value") |
| 96 |
} |
| 97 |
""", |
| 98 |
[ |
| 99 |
{ |
| 100 |
"message": "There can be only one argument named 'arg1'.", |
| 101 |
"locations": [(3, 21), (3, 36), (3, 51)], |
| 102 |
}, |
| 103 |
], |
| 104 |
) |
| 105 |
|
| 106 |
def duplicate_directive_arguments(): |
| 107 |
assert_errors( |
| 108 |
""" |
| 109 |
{ |
| 110 |
field @directive(arg1: "value", arg1: "value") |
| 111 |
} |
| 112 |
""", |
| 113 |
[ |
| 114 |
{ |
| 115 |
"message": "There can be only one argument named 'arg1'.", |
| 116 |
"locations": [(3, 32), (3, 47)], |
| 117 |
}, |
| 118 |
], |
| 119 |
) |
| 120 |
|
| 121 |
def many_duplicate_directive_arguments(): |
| 122 |
assert_errors( |
| 123 |
""" |
| 124 |
{ |
| 125 |
field @directive(arg1: "value", arg1: "value", arg1: "value") |
| 126 |
} |
| 127 |
""", |
| 128 |
[ |
| 129 |
{ |
| 130 |
"message": "There can be only one argument named 'arg1'.", |
| 131 |
"locations": [(3, 32), (3, 47), (3, 62)], |
| 132 |
}, |
| 133 |
], |
| 134 |
) |