Skip to content

Added GraphiQL template injection #20

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)