Skip to content

Commit f119c3b

Browse files
committed
Added schema str representation. Fixed #32
1 parent 9b635c8 commit f119c3b

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

graphene/core/schema.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
SynchronousExecutionMiddleware
77
from graphql.core.type import GraphQLSchema as _GraphQLSchema
88
from graphql.core.utils.introspection_query import introspection_query
9+
from graphql.core.utils.schema_printer import print_schema
910

1011
from graphene import signals
1112

@@ -89,6 +90,9 @@ def objecttype(self, type):
8990
objecttype) and issubclass(objecttype, BaseObjectType):
9091
return objecttype
9192

93+
def __str__(self):
94+
return print_schema(self.schema)
95+
9296
def setup(self):
9397
assert self.query, 'The base query type is not set'
9498
self.T(self.query)

graphene/core/tests/test_schema.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,22 @@ class MyType(ObjectType):
152152
schema.query = MyType
153153

154154
assert schema.T(t) == schema.T(MyType)
155+
156+
157+
def test_schema_str():
158+
expected = """
159+
interface Character {
160+
name: String
161+
}
162+
163+
type Human implements Character {
164+
name: String
165+
friends: [Character]
166+
pet: Pet
167+
}
168+
169+
type Pet {
170+
type: String
171+
}
172+
""".lstrip()
173+
assert str(schema) == expected

0 commit comments

Comments
 (0)