Skip to content

Commit

Permalink
Merge pull request #20 from lucascosta/graphiql_template
Browse files Browse the repository at this point in the history
Added GraphiQL template injection
  • Loading branch information
syrusakbary committed Dec 14, 2016
2 parents d42846e + 2128bf5 commit 838673e
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ class GraphQLView(View):
pretty = False
graphiql = False
graphiql_version = None
graphiql_template = None
middleware = None

methods = ['GET', 'POST', 'PUT', 'DELETE']
Expand Down Expand Up @@ -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,
Expand Down
9 changes: 5 additions & 4 deletions flask_graphql/render_graphiql.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@
</html>'''


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)

0 comments on commit 838673e

Please sign in to comment.