Skip to content

Commit ba7275f

Browse files
committed
chore: Improve error message when a schema has no "Query" type
1 parent c9363b2 commit ba7275f

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

src/hypothesis_graphql/_strategies/queries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
def query(schema: str) -> st.SearchStrategy:
99
parsed_schema = graphql.build_schema(schema)
1010
if parsed_schema.query_type is None:
11-
raise ValueError
11+
raise ValueError("Query type is not defined in the schema")
1212
return get_strategy_for_type(parsed_schema.query_type).map(make_query).map(graphql.print_ast)
1313

1414

test/test_queries.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import graphql
2+
import pytest
23
from hypothesis import given
34

45
import hypothesis_graphql.strategies as gql_st
@@ -26,3 +27,11 @@ def test(query):
2627
graphql.parse(query)
2728

2829
test()
30+
31+
32+
def test_missing_query():
33+
schema = """type Author {
34+
name: String
35+
}"""
36+
with pytest.raises(ValueError, match="Query type is not defined in the schema"):
37+
gql_st.query(schema)

0 commit comments

Comments
 (0)