Skip to content

Commit a78114a

Browse files
authored
Add support to persist GraphQL headers in GraphiQL (graphql-python#1209)
1 parent 07940aa commit a78114a

File tree

5 files changed

+23
-0
lines changed

5 files changed

+23
-0
lines changed

docs/settings.rst

+19
Original file line numberDiff line numberDiff line change
@@ -207,3 +207,22 @@ Default: ``True``
207207
GRAPHENE = {
208208
'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
209209
}
210+
211+
212+
``GRAPHIQL_SHOULD_PERSIST_HEADERS``
213+
---------------------
214+
215+
Set to ``True`` if you want to persist GraphiQL headers after refreshing the page.
216+
217+
This setting is passed to ``shouldPersistHeaders`` GraphiQL options, for details refer to GraphiQLDocs_.
218+
219+
.. _GraphiQLDocs: https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
220+
221+
222+
Default: ``False``
223+
224+
.. code:: python
225+
226+
GRAPHENE = {
227+
'GRAPHIQL_SHOULD_PERSIST_HEADERS': False,
228+
}

graphene_django/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
# This sets headerEditorEnabled GraphiQL option, for details go to
4242
# https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
4343
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
44+
"GRAPHIQL_SHOULD_PERSIST_HEADERS": False,
4445
"ATOMIC_MUTATIONS": False,
4546
}
4647

graphene_django/static/graphene_django/graphiql.js

+1
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@
178178
onEditVariables: onEditVariables,
179179
onEditOperationName: onEditOperationName,
180180
headerEditorEnabled: GRAPHENE_SETTINGS.graphiqlHeaderEditorEnabled,
181+
shouldPersistHeaders: GRAPHENE_SETTINGS.graphiqlShouldPersistHeaders,
181182
query: parameters.query,
182183
};
183184
if (parameters.variables) {

graphene_django/templates/graphene/graphiql.html

+1
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
subscriptionPath: "{{subscription_path}}",
4747
{% endif %}
4848
graphiqlHeaderEditorEnabled: {{ graphiql_header_editor_enabled|yesno:"true,false" }},
49+
graphiqlShouldPersistHeaders: {{ graphiql_should_persist_headers|yesno:"true,false" }},
4950
};
5051
</script>
5152
<script src="{% static 'graphene_django/graphiql.js' %}"></script>

graphene_django/views.py

+1
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,7 @@ def dispatch(self, request, *args, **kwargs):
162162
subscription_path=self.subscription_path,
163163
# GraphiQL headers tab,
164164
graphiql_header_editor_enabled=graphene_settings.GRAPHIQL_HEADER_EDITOR_ENABLED,
165+
graphiql_should_persist_headers=graphene_settings.GRAPHIQL_SHOULD_PERSIST_HEADERS,
165166
)
166167

167168
if self.batch:

0 commit comments

Comments
 (0)