Skip to content

Commit 0e2d9be

Browse files
committed
Fixed test schema with empty query. Fixed #409
1 parent ba29de5 commit 0e2d9be

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

graphene/tests/issues/test_313.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
import graphene
44
from graphene import resolve_only_args
55

6+
class Query(graphene.ObjectType):
7+
rand = graphene.String()
8+
69
class Success(graphene.ObjectType):
710
yeah = graphene.String()
811

@@ -45,7 +48,7 @@ def test_create_post():
4548
}
4649
'''
4750

48-
schema = graphene.Schema(mutation=Mutations)
51+
schema = graphene.Schema(query=Query, mutation=Mutations)
4952
result = schema.execute(query_string)
5053

5154
assert not result.errors

graphene/types/schema.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import inspect
12

23
from graphql import GraphQLSchema, graphql, is_type
34
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
@@ -7,6 +8,7 @@
78
from graphql.utils.schema_printer import print_schema
89

910
from .definitions import GrapheneGraphQLType
11+
from .objecttype import ObjectType
1012
from .typemap import TypeMap, is_graphene_type
1113

1214

@@ -20,6 +22,9 @@ class Schema(GraphQLSchema):
2022

2123
def __init__(self, query=None, mutation=None, subscription=None,
2224
directives=None, types=None, auto_camelcase=True):
25+
assert inspect.isclass(query) and issubclass(query, ObjectType), (
26+
'Schema query must be Object Type but got: {}.'
27+
).format(query)
2328
self._query = query
2429
self._mutation = mutation
2530
self._subscription = subscription
@@ -77,7 +82,10 @@ def execute(self, *args, **kwargs):
7782
return graphql(self, *args, **kwargs)
7883

7984
def introspect(self):
80-
return self.execute(introspection_query).data
85+
instrospection = self.execute(introspection_query)
86+
if instrospection.errors:
87+
raise instrospection.errors[0]
88+
return instrospection.data
8189

8290
def __str__(self):
8391
return print_schema(self)

0 commit comments

Comments
 (0)