From 2128bf54d03d833f30553c60204f80d9e807b83d Mon Sep 17 00:00:00 2001 From: Lucas Costa Date: Fri, 9 Dec 2016 17:05:45 -0200 Subject: [PATCH] Added GraphiQL template injection --- README.md | 4 ++-- flask_graphql/graphqlview.py | 2 ++ flask_graphql/render_graphiql.py | 9 +++++---- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1f69db3..6246ea9 100644 --- a/README.md +++ b/README.md @@ -23,8 +23,8 @@ This will add `/graphql` and `/graphiql` endpoints to your app. * `root_value`: The `root_value` you want to provide to `executor.execute`. * `pretty`: Whether or not you want the response to be pretty printed JSON. * `executor`: The `Executor` that you want to use to execute queries. - * `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly - from a browser (a useful tool for debugging and exploration). + * `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration). + * `graphiql_template`: Inject a Jinja template string to customize GraphiQL. You can also subclass `GraphQLView` and overwrite `get_root_value(self, request)` to have a dynamic root value per request. diff --git a/flask_graphql/graphqlview.py b/flask_graphql/graphqlview.py index 6e48e29..f130516 100644 --- a/flask_graphql/graphqlview.py +++ b/flask_graphql/graphqlview.py @@ -30,6 +30,7 @@ class GraphQLView(View): pretty = False graphiql = False graphiql_version = None + graphiql_template = None middleware = None methods = ['GET', 'POST', 'PUT', 'DELETE'] @@ -92,6 +93,7 @@ def dispatch_request(self): if show_graphiql: return render_graphiql( graphiql_version=self.graphiql_version, + graphiql_template=self.graphiql_template, query=query, variables=variables, operation_name=operation_name, diff --git a/flask_graphql/render_graphiql.py b/flask_graphql/render_graphiql.py index 856cc9d..12d8f4c 100644 --- a/flask_graphql/render_graphiql.py +++ b/flask_graphql/render_graphiql.py @@ -123,8 +123,9 @@ ''' -def render_graphiql(graphiql_version=None, **kwargs): - if not graphiql_version: - graphiql_version = GRAPHIQL_VERSION +def render_graphiql(graphiql_version=None, graphiql_template=None, **kwargs): + graphiql_version = graphiql_version or GRAPHIQL_VERSION + template = graphiql_template or TEMPLATE - return render_template_string(TEMPLATE, graphiql_version=graphiql_version, **kwargs) + return render_template_string( + template, graphiql_version=graphiql_version, **kwargs)