Skip to content

Commit 6e2d7c9

Browse files
Customizable HTML title in GraphiQL
1 parent 973d10f commit 6e2d7c9

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

flask_graphql/graphqlview.py

+2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class GraphQLView(View):
1919
graphiql = False
2020
graphiql_version = None
2121
graphiql_template = None
22+
graphiql_html_title = None
2223
middleware = None
2324
batch = False
2425

@@ -51,6 +52,7 @@ def render_graphiql(self, params, result):
5152
result=result,
5253
graphiql_version=self.graphiql_version,
5354
graphiql_template=self.graphiql_template,
55+
graphiql_html_title=self.graphiql_html_title,
5456
)
5557

5658
format_error = staticmethod(default_format_error)

flask_graphql/render_graphiql.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<!DOCTYPE html>
1313
<html>
1414
<head>
15+
<title>{{graphiql_html_title|default("GraphiQL", true)}}</title>
1516
<style>
1617
html, body {
1718
height: 100%;
@@ -123,13 +124,15 @@
123124
</html>'''
124125

125126

126-
def render_graphiql(params, result, graphiql_version=None, graphiql_template=None):
127+
def render_graphiql(params, result, graphiql_version=None,
128+
graphiql_template=None, graphiql_html_title=None):
127129
graphiql_version = graphiql_version or GRAPHIQL_VERSION
128130
template = graphiql_template or TEMPLATE
129131

130132
return render_template_string(
131133
template,
132134
graphiql_version=graphiql_version,
135+
graphiql_html_title=graphiql_html_title,
133136
result=result,
134137
params=params
135138
)

tests/test_graphiqlview.py

+11
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,14 @@ def test_graphiql_renders_pretty(client):
2626
).replace("\"","\\\"").replace("\n","\\n")
2727

2828
assert pretty_response in response.data.decode('utf-8')
29+
30+
31+
def test_graphiql_default_title(client):
32+
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
33+
assert '<title>GraphiQL</title>' in response.data.decode('utf-8')
34+
35+
36+
@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
37+
def test_graphiql_custom_title(client):
38+
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
39+
assert '<title>Awesome</title>' in response.data.decode('utf-8')

0 commit comments

Comments
 (0)