2019-05-07 22:22:08 +03:00
Settings
========
Graphene-Django can be customised using settings. This page explains each setting and their defaults.
Usage
-----
2023-09-06 10:29:58 +03:00
Add settings to your Django project by creating a Dictionary with name `` GRAPHENE `` in the project's `` settings.py `` :
2019-05-07 22:22:08 +03:00
.. code :: python
GRAPHENE = {
...
}
`` SCHEMA ``
----------
The location of the top-level `` Schema `` class.
Default: `` None ``
.. code :: python
GRAPHENE = {
'SCHEMA': 'path.to.schema.schema',
}
`` SCHEMA_OUTPUT ``
2019-06-14 14:33:37 +03:00
-----------------
2019-05-07 22:22:08 +03:00
The name of the file where the GraphQL schema output will go.
Default: `` schema.json ``
.. code :: python
GRAPHENE = {
'SCHEMA_OUTPUT': 'schema.json',
}
`` SCHEMA_INDENT ``
2019-06-14 14:33:37 +03:00
-----------------
2019-05-07 22:22:08 +03:00
The indentation level of the schema output.
Default: `` 2 ``
.. code :: python
GRAPHENE = {
'SCHEMA_INDENT': 2,
}
`` MIDDLEWARE ``
2019-06-14 14:33:37 +03:00
--------------
2019-05-07 22:22:08 +03:00
A tuple of middleware that will be executed for each GraphQL query.
See the `middleware documentation <https://docs.graphene-python.org/en/latest/execution/middleware/> `__ for more information.
Default: `` () ``
.. code :: python
GRAPHENE = {
'MIDDLEWARE': (
'path.to.my.middleware.class',
),
}
`` RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST ``
2019-06-14 14:33:37 +03:00
------------------------------------------
2019-05-07 22:22:08 +03:00
Enforces relay queries to have the `` first `` or `` last `` argument.
Default: `` False ``
.. code :: python
GRAPHENE = {
'RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST': False,
}
`` RELAY_CONNECTION_MAX_LIMIT ``
2019-06-14 14:33:37 +03:00
------------------------------
2019-05-07 22:22:08 +03:00
The maximum size of objects that can be requested through a relay connection.
Default: `` 100 ``
.. code :: python
GRAPHENE = {
'RELAY_CONNECTION_MAX_LIMIT': 100,
2019-05-07 22:23:26 +03:00
}
2019-07-09 00:22:08 +03:00
`` CAMELCASE_ERRORS ``
2020-07-12 16:42:31 +03:00
--------------------
2019-07-09 00:22:08 +03:00
When set to `` True `` field names in the `` errors `` object will be camel case.
By default they will be snake case.
Default: `` False ``
.. code :: python
GRAPHENE = {
'CAMELCASE_ERRORS': False,
}
# result = schema.execute(...)
print(result.errors)
# [
# {
# 'field': 'test_field',
# 'messages': ['This field is required.'],
# }
# ]
.. code :: python
GRAPHENE = {
'CAMELCASE_ERRORS': True,
}
# result = schema.execute(...)
print(result.errors)
# [
# {
# 'field': 'testField',
# 'messages': ['This field is required.'],
# }
# ]
2020-03-13 13:04:25 +03:00
2020-06-10 19:32:07 +03:00
`` DJANGO_CHOICE_FIELD_ENUM_V2_NAMING ``
2020-03-13 13:04:25 +03:00
--------------------------------------
2020-06-10 19:32:07 +03:00
Set to `` True `` to use the old naming format for the auto generated Enum types from Django choice fields. The old format looks like this: `` {object_name}_{field_name} ``
2020-03-13 13:04:25 +03:00
Default: `` False ``
`` DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME ``
2020-06-10 19:32:07 +03:00
----------------------------------------
2020-03-13 13:04:25 +03:00
Define the path of a function that takes the Django choice field and returns a string to completely customise the naming for the Enum type.
2020-06-10 19:32:07 +03:00
If set to a function then the `` DJANGO_CHOICE_FIELD_ENUM_V2_NAMING `` setting is ignored.
2020-03-13 13:04:25 +03:00
Default: `` None ``
.. code :: python
# myapp.utils
def enum_naming(field):
if isinstance(field.model, User):
return f"CustomUserEnum{field.name.title()}"
return f"CustomEnum{field.name.title()}"
GRAPHENE = {
'DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME': "myapp.utils.enum_naming"
}
2020-07-12 16:42:31 +03:00
`` SUBSCRIPTION_PATH ``
---------------------
Define an alternative URL path where subscription operations should be routed.
The GraphiQL interface will use this setting to intelligently route subscription operations. This is useful if you have more advanced infrastructure requirements that prevent websockets from being handled at the same path (e.g., a WSGI server listening at `` /graphql `` and an ASGI server listening at `` /ws/graphql `` ).
Default: `` None ``
.. code :: python
GRAPHENE = {
'SUBSCRIPTION_PATH': "/ws/graphql"
}
2020-08-07 12:13:26 +03:00
`` GRAPHIQL_HEADER_EDITOR_ENABLED ``
2022-09-26 01:56:22 +03:00
----------------------------------
2020-08-07 12:13:26 +03:00
GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables.
Set to `` False `` if you want to disable GraphiQL headers editor tab for some reason.
This setting is passed to `` headerEditorEnabled `` GraphiQL options, for details refer to GraphiQLDocs_.
Default: `` True ``
.. code :: python
GRAPHENE = {
'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
}
2022-09-24 17:41:14 +03:00
2022-09-26 01:56:22 +03:00
`` TESTING_ENDPOINT ``
--------------------
Define the graphql endpoint url used for the `GraphQLTestCase` class.
Default: `` /graphql ``
.. code :: python
GRAPHENE = {
'TESTING_ENDPOINT': '/customEndpoint'
}
2022-09-24 17:41:14 +03:00
`` GRAPHIQL_SHOULD_PERSIST_HEADERS ``
2023-05-24 15:55:20 +03:00
-----------------------------------
2022-09-24 17:41:14 +03:00
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_.
Default: `` False ``
.. code :: python
GRAPHENE = {
'GRAPHIQL_SHOULD_PERSIST_HEADERS': False,
}
2023-09-13 09:49:01 +03:00
`` GRAPHIQL_INPUT_VALUE_DEPRECATION ``
------------------------------------
Set to `` True `` if you want GraphiQL to show any deprecated fields on input object types' docs.
For example, having this schema:
.. code :: python
class MyMutationInputType(graphene.InputObjectType):
old_field = graphene.String(deprecation_reason="You should now use 'newField' instead.")
new_field = graphene.String()
class MyMutation(graphene.Mutation):
class Arguments:
input = types.MyMutationInputType()
GraphiQL will add a `` Show Deprecated Fields `` button to toggle information display on `` oldField `` and its deprecation
reason. Otherwise, you would get neither a button nor any information at all on `` oldField `` .
This setting is passed to `` inputValueDeprecation `` GraphiQL options, for details refer to GraphiQLDocs_.
Default: `` False ``
.. code :: python
GRAPHENE = {
'GRAPHIQL_INPUT_VALUE_DEPRECATION': False,
}
.. _GraphiQLDocs: https://graphiql-test.netlify.app/typedoc/modules/graphiql_react#graphiqlprovider-2