Debian Codegraph @

tests/benchmarks/test_validate_invalid_gql.py

raw
1 from graphql import build_schema, parse, validate
2
3 from ..fixtures import big_schema_sdl # noqa: F401
4
5
6 def test_validate_invalid_query(benchmark, big_schema_sdl): # noqa: F811
7 schema = build_schema(big_schema_sdl, assume_valid=True)
8 query_ast = parse("""
9 {
10 unknownField
11 ... on unknownType {
12 anotherUnknownField
13 ...unknownFragment
14 }
15 }
16
17 fragment TestFragment on anotherUnknownType {
18 yetAnotherUnknownField
19 }
20 """)
21 result = benchmark(lambda: validate(schema, query_ast))
22 assert result == [
23 {
24 "message": "Cannot query field 'unknownField' on type 'Query'.",
25 "locations": [(3, 11)],
26 },
27 {"message": "Unknown type 'unknownType'.", "locations": [(4, 18)]},
28 {"message": "Unknown fragment 'unknownFragment'.", "locations": [(6, 16)]},
29 {"message": "Unknown type 'anotherUnknownType'.", "locations": [(10, 34)]},
30 {"message": "Fragment 'TestFragment' is never used.", "locations": [(10, 9)]},
31 ]