mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-11 12:16:58 +03:00
Fixed test schema with empty query. Fixed #409
This commit is contained in:
parent
ba29de5670
commit
0e2d9be6a8
|
@ -3,6 +3,9 @@
|
||||||
import graphene
|
import graphene
|
||||||
from graphene import resolve_only_args
|
from graphene import resolve_only_args
|
||||||
|
|
||||||
|
class Query(graphene.ObjectType):
|
||||||
|
rand = graphene.String()
|
||||||
|
|
||||||
class Success(graphene.ObjectType):
|
class Success(graphene.ObjectType):
|
||||||
yeah = graphene.String()
|
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)
|
result = schema.execute(query_string)
|
||||||
|
|
||||||
assert not result.errors
|
assert not result.errors
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
import inspect
|
||||||
|
|
||||||
from graphql import GraphQLSchema, graphql, is_type
|
from graphql import GraphQLSchema, graphql, is_type
|
||||||
from graphql.type.directives import (GraphQLDirective, GraphQLIncludeDirective,
|
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 graphql.utils.schema_printer import print_schema
|
||||||
|
|
||||||
from .definitions import GrapheneGraphQLType
|
from .definitions import GrapheneGraphQLType
|
||||||
|
from .objecttype import ObjectType
|
||||||
from .typemap import TypeMap, is_graphene_type
|
from .typemap import TypeMap, is_graphene_type
|
||||||
|
|
||||||
|
|
||||||
|
@ -20,6 +22,9 @@ class Schema(GraphQLSchema):
|
||||||
|
|
||||||
def __init__(self, query=None, mutation=None, subscription=None,
|
def __init__(self, query=None, mutation=None, subscription=None,
|
||||||
directives=None, types=None, auto_camelcase=True):
|
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._query = query
|
||||||
self._mutation = mutation
|
self._mutation = mutation
|
||||||
self._subscription = subscription
|
self._subscription = subscription
|
||||||
|
@ -77,7 +82,10 @@ class Schema(GraphQLSchema):
|
||||||
return graphql(self, *args, **kwargs)
|
return graphql(self, *args, **kwargs)
|
||||||
|
|
||||||
def introspect(self):
|
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):
|
def __str__(self):
|
||||||
return print_schema(self)
|
return print_schema(self)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user