diff --git a/docs/settings.rst b/docs/settings.rst index fa02347..5bffd08 100644 --- a/docs/settings.rst +++ b/docs/settings.rst @@ -220,4 +220,23 @@ Default: ``/graphql`` GRAPHENE = { 'TESTING_ENDPOINT': '/customEndpoint' - } \ No newline at end of file + } + + +``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, + } diff --git a/graphene_django/settings.py b/graphene_django/settings.py index aa66c72..6f62326 100644 --- a/graphene_django/settings.py +++ b/graphene_django/settings.py @@ -41,6 +41,7 @@ DEFAULTS = { # 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, "TESTING_ENDPOINT": "/graphql", } diff --git a/graphene_django/static/graphene_django/graphiql.js b/graphene_django/static/graphene_django/graphiql.js index f457f65..f6be32c 100644 --- a/graphene_django/static/graphene_django/graphiql.js +++ b/graphene_django/static/graphene_django/graphiql.js @@ -178,6 +178,7 @@ onEditVariables: onEditVariables, onEditOperationName: onEditOperationName, headerEditorEnabled: GRAPHENE_SETTINGS.graphiqlHeaderEditorEnabled, + shouldPersistHeaders: GRAPHENE_SETTINGS.graphiqlShouldPersistHeaders, query: parameters.query, }; if (parameters.variables) { diff --git a/graphene_django/templates/graphene/graphiql.html b/graphene_django/templates/graphene/graphiql.html index cec4893..3685692 100644 --- a/graphene_django/templates/graphene/graphiql.html +++ b/graphene_django/templates/graphene/graphiql.html @@ -46,6 +46,7 @@ add "&raw" to the end of the URL within a browser. subscriptionPath: "{{subscription_path}}", {% endif %} graphiqlHeaderEditorEnabled: {{ graphiql_header_editor_enabled|yesno:"true,false" }}, + graphiqlShouldPersistHeaders: {{ graphiql_should_persist_headers|yesno:"true,false" }}, }; diff --git a/graphene_django/views.py b/graphene_django/views.py index f533f70..bf333a9 100644 --- a/graphene_django/views.py +++ b/graphene_django/views.py @@ -162,6 +162,7 @@ class GraphQLView(View): 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: