Skip to content

Commit 476edf3

Browse files
committed
Accept Graphene wrapped GraphQL schemas
1 parent 1ccebee commit 476edf3

File tree

5 files changed

+25
-15
lines changed

5 files changed

+25
-15
lines changed

Diff for: graphql_server/aiohttp/graphqlview.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,11 @@ def __init__(self, **kwargs):
5656
if hasattr(self, key):
5757
setattr(self, key, value)
5858

59-
assert isinstance(
60-
self.schema, GraphQLSchema
61-
), "A Schema is required to be provided to GraphQLView."
59+
if not isinstance(self.schema, GraphQLSchema):
60+
# maybe the GraphQL schema is wrapped in a Graphene schema
61+
self.schema = getattr(self.schema, "graphql_schema", None)
62+
if not isinstance(self.schema, GraphQLSchema):
63+
raise TypeError("A Schema is required to be provided to GraphQLView.")
6264

6365
def get_root_value(self):
6466
return self.root_value

Diff for: graphql_server/flask/graphqlview.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def __init__(self, **kwargs):
5555
if hasattr(self, key):
5656
setattr(self, key, value)
5757

58-
assert isinstance(
59-
self.schema, GraphQLSchema
60-
), "A Schema is required to be provided to GraphQLView."
58+
if not isinstance(self.schema, GraphQLSchema):
59+
# maybe the GraphQL schema is wrapped in a Graphene schema
60+
self.schema = getattr(self.schema, "graphql_schema", None)
61+
if not isinstance(self.schema, GraphQLSchema):
62+
raise TypeError("A Schema is required to be provided to GraphQLView.")
6163

6264
def get_root_value(self):
6365
return self.root_value

Diff for: graphql_server/quart/graphqlview.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,11 @@ def __init__(self, **kwargs):
5757
if hasattr(self, key):
5858
setattr(self, key, value)
5959

60-
assert isinstance(
61-
self.schema, GraphQLSchema
62-
), "A Schema is required to be provided to GraphQLView."
60+
if not isinstance(self.schema, GraphQLSchema):
61+
# maybe the GraphQL schema is wrapped in a Graphene schema
62+
self.schema = getattr(self.schema, "graphql_schema", None)
63+
if not isinstance(self.schema, GraphQLSchema):
64+
raise TypeError("A Schema is required to be provided to GraphQLView.")
6365

6466
def get_root_value(self):
6567
return self.root_value

Diff for: graphql_server/sanic/graphqlview.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,11 @@ def __init__(self, **kwargs):
5858
if hasattr(self, key):
5959
setattr(self, key, value)
6060

61-
assert isinstance(
62-
self.schema, GraphQLSchema
63-
), "A Schema is required to be provided to GraphQLView."
61+
if not isinstance(self.schema, GraphQLSchema):
62+
# maybe the GraphQL schema is wrapped in a Graphene schema
63+
self.schema = getattr(self.schema, "graphql_schema", None)
64+
if not isinstance(self.schema, GraphQLSchema):
65+
raise TypeError("A Schema is required to be provided to GraphQLView.")
6466

6567
def get_root_value(self):
6668
return self.root_value

Diff for: graphql_server/webob/graphqlview.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,11 @@ def __init__(self, **kwargs):
5555
if hasattr(self, key):
5656
setattr(self, key, value)
5757

58-
assert isinstance(
59-
self.schema, GraphQLSchema
60-
), "A Schema is required to be provided to GraphQLView."
58+
if not isinstance(self.schema, GraphQLSchema):
59+
# maybe the GraphQL schema is wrapped in a Graphene schema
60+
self.schema = getattr(self.schema, "graphql_schema", None)
61+
if not isinstance(self.schema, GraphQLSchema):
62+
raise TypeError("A Schema is required to be provided to GraphQLView.")
6163

6264
def get_root_value(self):
6365
return self.root_value

0 commit comments

Comments
 (0)