Skip to content

Add support to persist GraphQL headers in GraphiQL #1209

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
19 changes: 19 additions & 0 deletions docs/settings.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,3 +207,22 @@ Default: ``True``
GRAPHENE = {
'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
}


``GRAPHIQL_SHOULD_PERSIST_HEADERS``
---------------------

Set to ``True`` if you want to persist GraphiQL headers after refreshing the page.

This setting is passed to ``shouldPersistHeaders`` GraphiQL options, for details refer to GraphiQLDocs_.

.. _GraphiQLDocs: https://github.com/graphql/graphiql/tree/main/packages/graphiql#options


Default: ``False``

.. code:: python

GRAPHENE = {
'GRAPHIQL_SHOULD_PERSIST_HEADERS': False,
}
1 change: 1 addition & 0 deletions graphene_django/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
# This sets headerEditorEnabled GraphiQL option, for details go to
# https://github.com/graphql/graphiql/tree/main/packages/graphiql#options
"GRAPHIQL_HEADER_EDITOR_ENABLED": True,
"GRAPHIQL_SHOULD_PERSIST_HEADERS": False,
"ATOMIC_MUTATIONS": False,
}

Expand Down
1 change: 1 addition & 0 deletions graphene_django/static/graphene_django/graphiql.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,7 @@
onEditVariables: onEditVariables,
onEditOperationName: onEditOperationName,
headerEditorEnabled: GRAPHENE_SETTINGS.graphiqlHeaderEditorEnabled,
shouldPersistHeaders: GRAPHENE_SETTINGS.graphiqlShouldPersistHeaders,
query: parameters.query,
};
if (parameters.variables) {
Expand Down
1 change: 1 addition & 0 deletions graphene_django/templates/graphene/graphiql.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
subscriptionPath: "{{subscription_path}}",
{% endif %}
graphiqlHeaderEditorEnabled: {{ graphiql_header_editor_enabled|yesno:"true,false" }},
graphiqlShouldPersistHeaders: {{ graphiql_should_persist_headers|yesno:"true,false" }},
};
</script>
<script src="{% static 'graphene_django/graphiql.js' %}"></script>
Expand Down
1 change: 1 addition & 0 deletions graphene_django/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def dispatch(self, request, *args, **kwargs):
subscription_path=self.subscription_path,
# GraphiQL headers tab,
graphiql_header_editor_enabled=graphene_settings.GRAPHIQL_HEADER_EDITOR_ENABLED,
graphiql_should_persist_headers=graphene_settings.GRAPHIQL_SHOULD_PERSIST_HEADERS,
)

if self.batch:
Expand Down