Skip to content

Commit 2128bf5

Browse files
committed
Added GraphiQL template injection
1 parent d42846e commit 2128bf5

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

Diff for: README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ This will add `/graphql` and `/graphiql` endpoints to your app.
2323
* `root_value`: The `root_value` you want to provide to `executor.execute`.
2424
* `pretty`: Whether or not you want the response to be pretty printed JSON.
2525
* `executor`: The `Executor` that you want to use to execute queries.
26-
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly
27-
from a browser (a useful tool for debugging and exploration).
26+
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
27+
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
2828

2929
You can also subclass `GraphQLView` and overwrite `get_root_value(self, request)` to have a dynamic root value
3030
per request.

Diff for: flask_graphql/graphqlview.py

+2
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class GraphQLView(View):
3030
pretty = False
3131
graphiql = False
3232
graphiql_version = None
33+
graphiql_template = None
3334
middleware = None
3435

3536
methods = ['GET', 'POST', 'PUT', 'DELETE']
@@ -92,6 +93,7 @@ def dispatch_request(self):
9293
if show_graphiql:
9394
return render_graphiql(
9495
graphiql_version=self.graphiql_version,
96+
graphiql_template=self.graphiql_template,
9597
query=query,
9698
variables=variables,
9799
operation_name=operation_name,

Diff for: flask_graphql/render_graphiql.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@
123123
</html>'''
124124

125125

126-
def render_graphiql(graphiql_version=None, **kwargs):
127-
if not graphiql_version:
128-
graphiql_version = GRAPHIQL_VERSION
126+
def render_graphiql(graphiql_version=None, graphiql_template=None, **kwargs):
127+
graphiql_version = graphiql_version or GRAPHIQL_VERSION
128+
template = graphiql_template or TEMPLATE
129129

130-
return render_template_string(TEMPLATE, graphiql_version=graphiql_version, **kwargs)
130+
return render_template_string(
131+
template, graphiql_version=graphiql_version, **kwargs)

0 commit comments

Comments
 (0)