Fixed test schema with empty query. Fixed #409

This commit is contained in:
Syrus Akbary 2017-02-20 21:41:11 -08:00
parent ba29de5670
commit 0e2d9be6a8
2 changed files with 13 additions and 2 deletions

View File

@ -3,6 +3,9 @@
import graphene
from graphene import resolve_only_args
class Query(graphene.ObjectType):
rand = graphene.String()
class Success(graphene.ObjectType):
yeah = graphene.String()
@ -45,7 +48,7 @@ def test_create_post():
}
'''
schema = graphene.Schema(mutation=Mutations)
schema = graphene.Schema(query=Query, mutation=Mutations)
result = schema.execute(query_string)
assert not result.errors

View File

@ -1,3 +1,4 @@
import inspect
from graphql import GraphQLSchema, graphql, is_type
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
@ -7,6 +8,7 @@ from graphql.utils.introspection_query import introspection_query
from graphql.utils.schema_printer import print_schema
from .definitions import GrapheneGraphQLType
from .objecttype import ObjectType
from .typemap import TypeMap, is_graphene_type
@ -20,6 +22,9 @@ class Schema(GraphQLSchema):
def __init__(self, query=None, mutation=None, subscription=None,
directives=None, types=None, auto_camelcase=True):
assert inspect.isclass(query) and issubclass(query, ObjectType), (
'Schema query must be Object Type but got: {}.'
).format(query)
self._query = query
self._mutation = mutation
self._subscription = subscription
@ -77,7 +82,10 @@ class Schema(GraphQLSchema):
return graphql(self, *args, **kwargs)
def introspect(self):
return self.execute(introspection_query).data
instrospection = self.execute(introspection_query)
if instrospection.errors:
raise instrospection.errors[0]
return instrospection.data
def __str__(self):
return print_schema(self)