Skip to content

Customizable HTML title in GraphiQL #30

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
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
2 changes: 2 additions & 0 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class GraphQLView(View):
graphiql = False
graphiql_version = None
graphiql_template = None
graphiql_html_title = None
middleware = None
batch = False

Expand Down Expand Up @@ -51,6 +52,7 @@ def render_graphiql(self, params, result):
result=result,
graphiql_version=self.graphiql_version,
graphiql_template=self.graphiql_template,
graphiql_html_title=self.graphiql_html_title,
)

format_error = staticmethod(default_format_error)
Expand Down
5 changes: 4 additions & 1 deletion flask_graphql/render_graphiql.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<!DOCTYPE html>
<html>
<head>
<title>{{graphiql_html_title|default("GraphiQL", true)}}</title>
<style>
html, body {
height: 100%;
Expand Down Expand Up @@ -123,13 +124,15 @@
</html>'''


def render_graphiql(params, result, graphiql_version=None, graphiql_template=None):
def render_graphiql(params, result, graphiql_version=None,
graphiql_template=None, graphiql_html_title=None):
graphiql_version = graphiql_version or GRAPHIQL_VERSION
template = graphiql_template or TEMPLATE

return render_template_string(
template,
graphiql_version=graphiql_version,
graphiql_html_title=graphiql_html_title,
result=result,
params=params
)
11 changes: 11 additions & 0 deletions tests/test_graphiqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,14 @@ def test_graphiql_renders_pretty(client):
).replace("\"","\\\"").replace("\n","\\n")

assert pretty_response in response.data.decode('utf-8')


def test_graphiql_default_title(client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
assert '<title>GraphiQL</title>' in response.data.decode('utf-8')


@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
def test_graphiql_custom_title(client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
assert '<title>Awesome</title>' in response.data.decode('utf-8')