File: test_unique_variable_names.py

package info (click to toggle)
graphql-core 3.2.6-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,384 kB
  • sloc: python: 45,812; makefile: 26; sh: 13
file content (42 lines) | stat: -rw-r--r-- 1,333 bytes parent folder | download | duplicates (2)
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
from functools import partial

from graphql.validation import UniqueVariableNamesRule

from .harness import assert_validation_errors

assert_errors = partial(assert_validation_errors, UniqueVariableNamesRule)

assert_valid = partial(assert_errors, errors=[])


def describe_validate_unique_variable_names():
    def unique_variable_names():
        assert_valid(
            """
            query A($x: Int, $y: String) { __typename }
            query B($x: String, $y: Int) { __typename }
            """
        )

    def duplicate_variable_names():
        assert_errors(
            """
            query A($x: Int, $x: Int, $x: String) { __typename }
            query B($x: String, $x: Int) { __typename }
            query C($x: Int, $x: Int) { __typename }
            """,
            [
                {
                    "message": "There can be only one variable named '$x'.",
                    "locations": [(2, 22), (2, 31), (2, 40)],
                },
                {
                    "message": "There can be only one variable named '$x'.",
                    "locations": [(3, 22), (3, 34)],
                },
                {
                    "message": "There can be only one variable named '$x'.",
                    "locations": [(4, 22), (4, 31)],
                },
            ],
        )