File: test_validate_invalid_gql.py

package info (click to toggle)
graphql-core 3.2.7-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 5,452 kB
  • sloc: python: 46,922; makefile: 26; sh: 13
file content (33 lines) | stat: -rw-r--r-- 1,094 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
from graphql import build_schema, parse, validate

from ..fixtures import big_schema_sdl  # noqa: F401


def test_validate_invalid_query(benchmark, big_schema_sdl):  # noqa: F811
    schema = build_schema(big_schema_sdl, assume_valid=True)
    query_ast = parse(
        """
        {
          unknownField
          ... on unknownType {
            anotherUnknownField
            ...unknownFragment
          }
        }

        fragment TestFragment on anotherUnknownType {
          yetAnotherUnknownField
        }
        """
    )
    result = benchmark(lambda: validate(schema, query_ast))
    assert result == [
        {
            "message": "Cannot query field 'unknownField' on type 'Query'.",
            "locations": [(3, 11)],
        },
        {"message": "Unknown type 'unknownType'.", "locations": [(4, 18)]},
        {"message": "Unknown fragment 'unknownFragment'.", "locations": [(6, 16)]},
        {"message": "Unknown type 'anotherUnknownType'.", "locations": [(10, 34)]},
        {"message": "Fragment 'TestFragment' is never used.", "locations": [(10, 9)]},
    ]