mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-02 12:44:15 +03:00
Added schema str representation
This commit is contained in:
parent
9b635c848c
commit
fca0ab4f4c
|
@ -6,6 +6,7 @@ from graphql.core.execution.middlewares.sync import \
|
||||||
SynchronousExecutionMiddleware
|
SynchronousExecutionMiddleware
|
||||||
from graphql.core.type import GraphQLSchema as _GraphQLSchema
|
from graphql.core.type import GraphQLSchema as _GraphQLSchema
|
||||||
from graphql.core.utils.introspection_query import introspection_query
|
from graphql.core.utils.introspection_query import introspection_query
|
||||||
|
from graphql.core.utils.schema_printer import print_schema
|
||||||
|
|
||||||
from graphene import signals
|
from graphene import signals
|
||||||
|
|
||||||
|
@ -89,6 +90,9 @@ class Schema(object):
|
||||||
objecttype) and issubclass(objecttype, BaseObjectType):
|
objecttype) and issubclass(objecttype, BaseObjectType):
|
||||||
return objecttype
|
return objecttype
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return print_schema(self.schema)
|
||||||
|
|
||||||
def setup(self):
|
def setup(self):
|
||||||
assert self.query, 'The base query type is not set'
|
assert self.query, 'The base query type is not set'
|
||||||
self.T(self.query)
|
self.T(self.query)
|
||||||
|
|
|
@ -152,3 +152,22 @@ def test_lazytype():
|
||||||
schema.query = MyType
|
schema.query = MyType
|
||||||
|
|
||||||
assert schema.T(t) == schema.T(MyType)
|
assert schema.T(t) == schema.T(MyType)
|
||||||
|
|
||||||
|
|
||||||
|
def test_schema_str():
|
||||||
|
expected = """
|
||||||
|
interface Character {
|
||||||
|
name: String
|
||||||
|
}
|
||||||
|
|
||||||
|
type Human implements Character {
|
||||||
|
name: String
|
||||||
|
friends: [Character]
|
||||||
|
pet: Pet
|
||||||
|
}
|
||||||
|
|
||||||
|
type Pet {
|
||||||
|
type: String
|
||||||
|
}
|
||||||
|
""".lstrip()
|
||||||
|
assert str(schema) == expected
|
||||||
|
|
Loading…
Reference in New Issue
Block a user