Skip to content

Commit

Permalink
Merge 6e2d7c9 into 973d10f
Browse files Browse the repository at this point in the history
  • Loading branch information
singingwolfboy committed Aug 14, 2017
2 parents 973d10f + 6e2d7c9 commit cc7bf1f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
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')

0 comments on commit cc7bf1f

Please sign in to comment.