8000 Add benchmark for validating invalid query · graphql-python/graphql-core@e024793 · GitHub
[go: up one dir, main page]

Skip to content

Commit e024793

Browse files
committed
Add benchmark for validating invalid query
Replicates graphql/graphql-js@e591e95
1 parent 8f0eae6 commit e024793

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The current version 3.0.0a2 of GraphQL-core is up-to-date
1616
with GraphQL.js version 14.4.2.
1717

1818
All parts of the API are covered by an extensive test suite
19-
of currently 1932 unit tests.
19+
of currently 1933 unit tests.
2020

2121

2222
## Documentation
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from graphql import build_schema, parse, validate
2+
3+
# noinspection PyUnresolvedReferences
4+
from ..fixtures import big_schema_sdl # noqa: F401
5+
6+
7+
def test_validate_invalid_query(benchmark, big_schema_sdl): # noqa: F811
8+
schema = build_schema(big_schema_sdl, assume_valid=True)
9+
query_ast = parse(
10+
"""
11+
{
12+
unknownField
13+
... on unknownType {
14+
anotherUnknownField
15+
...unknownFragment
16+
}
17+
}
18+
19+
fragment TestFragment on anotherUnknownType {
20+
yetAnotherUnknownField
21+
}
22+
"""
23+
)
24+
result = benchmark(lambda: validate(schema, query_ast))
25+
assert result == [
26+
{
27+
"message": "Cannot query field 'unknownField' on type 'Query'.",
28+
"locations": [(3, 11)],
29+
},
30+
{
31+
"message": "Unknown type 'unknownType'. Did you mean 'UnknownSignature'?",
32+
"locations": [(4, 18)],
33+
},
34+
{"message": "Unknown fragment 'unknownFragment'.", "locations": [(6, 16)]},
35+
{"message": "Unknown type 'anotherUnknownType'.", "locations": [(10, 34)]},
36+
{"message": "Fragment 'TestFragment' is never used.", "locations": [(10, 9)]},
37+
]

0 commit comments

Comments
 (0)
0