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
|
from functools import partial
from graphql.utilities import build_schema
from graphql.validation.rules.unique_directive_names import UniqueDirectiveNamesRule
from .harness import assert_sdl_validation_errors
assert_errors = partial(assert_sdl_validation_errors, UniqueDirectiveNamesRule)
assert_valid = partial(assert_errors, errors=[])
def describe_validate_unique_directive_names():
def no_directive():
assert_valid(
"""
type Foo
"""
)
def one_directive():
assert_valid(
"""
directive @foo on SCHEMA
"""
)
def many_directives():
assert_valid(
"""
directive @foo on SCHEMA
directive @bar on SCHEMA
directive @baz on SCHEMA
"""
)
def directive_and_non_directive_definitions_named_the_same():
assert_valid(
"""
query foo { __typename }
fragment foo on foo { __typename }
type foo
directive @foo on SCHEMA
"""
)
def directives_named_the_same():
assert_errors(
"""
directive @foo on SCHEMA
directive @foo on SCHEMA
""",
[
{
"message": "There can be only one directive named '@foo'.",
"locations": [(2, 24), (4, 24)],
}
],
)
def adding_new_directive_to_existing_schema():
schema = build_schema("directive @foo on SCHEMA")
assert_valid("directive @bar on SCHEMA", schema=schema)
def adding_new_directive_with_standard_name_to_existing_schema():
schema = build_schema("type foo")
assert_errors(
"directive @skip on SCHEMA",
[
{
"message": "Directive '@skip' already exists in the schema."
" It cannot be redefined.",
"locations": [(1, 12)],
}
],
schema,
)
def adding_new_directive_to_existing_schema_with_same_named_type():
schema = build_schema("type foo")
assert_valid("directive @foo on SCHEMA", schema=schema)
def adding_conflicting_directives_to_existing_schema():
schema = build_schema("directive @foo on SCHEMA")
assert_errors(
"directive @foo on SCHEMA",
[
{
"message": "Directive '@foo' already exists in the schema."
" It cannot be redefined.",
"locations": [(1, 12)],
}
],
schema,
)
|