| 1 |
from functools import partial |
| 2 |
|
| 3 |
from graphql.validation.rules.unique_argument_definition_names import ( |
| 4 |
UniqueArgumentDefinitionNamesRule, |
| 5 |
) |
| 6 |
|
| 7 |
from .harness import assert_sdl_validation_errors |
| 8 |
|
| 9 |
assert_sdl_errors = partial( |
| 10 |
assert_sdl_validation_errors, UniqueArgumentDefinitionNamesRule |
| 11 |
) |
| 12 |
|
| 13 |
assert_sdl_valid = partial(assert_sdl_errors, errors=[]) |
| 14 |
|
| 15 |
|
| 16 |
def describe_validate_unique_argument_definition_names(): |
| 17 |
def no_args(): |
| 18 |
assert_sdl_valid(""" |
| 19 |
type SomeObject { |
| 20 |
someField: String |
| 21 |
} |
| 22 |
|
| 23 |
interface SomeInterface { |
| 24 |
someField: String |
| 25 |
} |
| 26 |
|
| 27 |
directive @someDirective on QUERY |
| 28 |
""") |
| 29 |
|
| 30 |
def one_argument(): |
| 31 |
assert_sdl_valid(""" |
| 32 |
type SomeObject { |
| 33 |
someField(foo: String): String |
| 34 |
} |
| 35 |
|
| 36 |
interface SomeInterface { |
| 37 |
someField(foo: String): String |
| 38 |
} |
| 39 |
|
| 40 |
extend type SomeObject { |
| 41 |
anotherField(foo: String): String |
| 42 |
} |
| 43 |
|
| 44 |
extend interface SomeInterface { |
| 45 |
anotherField(foo: String): String |
| 46 |
} |
| 47 |
|
| 48 |
directive @someDirective(foo: String) on QUERY |
| 49 |
""") |
| 50 |
|
| 51 |
def multiple_arguments(): |
| 52 |
assert_sdl_valid(""" |
| 53 |
type SomeObject { |
| 54 |
someField( |
| 55 |
foo: String |
| 56 |
bar: String |
| 57 |
): String |
| 58 |
} |
| 59 |
|
| 60 |
interface SomeInterface { |
| 61 |
someField( |
| 62 |
foo: String |
| 63 |
bar: String |
| 64 |
): String |
| 65 |
} |
| 66 |
|
| 67 |
extend type SomeObject { |
| 68 |
anotherField( |
| 69 |
foo: String |
| 70 |
bar: String |
| 71 |
): String |
| 72 |
} |
| 73 |
|
| 74 |
extend interface SomeInterface { |
| 75 |
anotherField( |
| 76 |
foo: String |
| 77 |
bar: String |
| 78 |
): String |
| 79 |
} |
| 80 |
|
| 81 |
directive @someDirective( |
| 82 |
foo: String |
| 83 |
bar: String |
| 84 |
) on QUERY |
| 85 |
""") |
| 86 |
|
| 87 |
def duplicating_arguments(): |
| 88 |
assert_sdl_errors( |
| 89 |
""" |
| 90 |
type SomeObject { |
| 91 |
someField( |
| 92 |
foo: String |
| 93 |
bar: String |
| 94 |
foo: String |
| 95 |
): String |
| 96 |
} |
| 97 |
|
| 98 |
interface SomeInterface { |
| 99 |
someField( |
| 100 |
foo: String |
| 101 |
bar: String |
| 102 |
foo: String |
| 103 |
): String |
| 104 |
} |
| 105 |
|
| 106 |
extend type SomeObject { |
| 107 |
anotherField( |
| 108 |
foo: String |
| 109 |
bar: String |
| 110 |
bar: String |
| 111 |
): String |
| 112 |
} |
| 113 |
|
| 114 |
extend interface SomeInterface { |
| 115 |
anotherField( |
| 116 |
bar: String |
| 117 |
foo: String |
| 118 |
foo: String |
| 119 |
): String |
| 120 |
} |
| 121 |
|
| 122 |
directive @someDirective( |
| 123 |
foo: String |
| 124 |
bar: String |
| 125 |
foo: String |
| 126 |
) on QUERY |
| 127 |
""", |
| 128 |
[ |
| 129 |
{ |
| 130 |
"message": "Argument 'SomeObject.someField(foo:)'" |
| 131 |
" can only be defined once.", |
| 132 |
"locations": [(4, 17), (6, 17)], |
| 133 |
}, |
| 134 |
{ |
| 135 |
"message": "Argument 'SomeInterface.someField(foo:)'" |
| 136 |
" can only be defined once.", |
| 137 |
"locations": [(12, 17), (14, 17)], |
| 138 |
}, |
| 139 |
{ |
| 140 |
"message": "Argument 'SomeObject.anotherField(bar:)'" |
| 141 |
" can only be defined once.", |
| 142 |
"locations": [(21, 17), (22, 17)], |
| 143 |
}, |
| 144 |
{ |
| 145 |
"message": "Argument 'SomeInterface.anotherField(foo:)'" |
| 146 |
" can only be defined once.", |
| 147 |
"locations": [(29, 17), (30, 17)], |
| 148 |
}, |
| 149 |
{ |
| 150 |
"message": "Argument '@someDirective(foo:)'" |
| 151 |
" can only be defined once.", |
| 152 |
"locations": [(35, 15), (37, 15)], |
| 153 |
}, |
| 154 |
], |
| 155 |
) |