15.Settings设置

Graphene-Django can be customised using settings. This page explains each setting and their defaults.

Graphene-Django可以使用设置进行定制。本页说明每个设置及其默认值。

Usage 用法

Add settings to your Django project by creating a Dictonary with name GRAPHENE in the project’s settings.py:

通过在Django项目的settings.py中创建名为GRAPHENE的口述语句,向Django项目添加设置:

GRAPHENE = {
    ...
}

SCHEMA

The location of the top-level Schema class.

顶级Schema类的位置。

Default: None

GRAPHENE = {
    'SCHEMA': 'path.to.schema.schema',
}

SCHEMA_OUTPUT

The name of the file where the GraphQL schema output will go.

GraphQL架构输出将放在其中的文件的名称。

Default: schema.json

GRAPHENE = {
    'SCHEMA_OUTPUT': 'schema.json',
}

SCHEMA_INDENT

The indentation level of the schema output.

架构输出的缩进级别。

Default: 2

GRAPHENE = {
    'SCHEMA_INDENT': 2,
}

MIDDLEWARE

A tuple of middleware that will be executed for each GraphQL query.

将为每个GraphQL查询执行的中间件元组。

See the middleware documentation for more information.

有关更多信息,请参阅中间件文档

Default: ()

GRAPHENE = {
    'MIDDLEWARE': (
        'path.to.my.middleware.class',
    ),
}

RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST

Enforces relay queries to have the first or last argument.

强制中继查询具有firstlast参数。

Default: False

GRAPHENE = {
    'RELAY_CONNECTION_ENFORCE_FIRST_OR_LAST': False,
}

RELAY_CONNECTION_MAX_LIMIT

The maximum size of objects that can be requested through a relay connection.

通过中继连接可以请求的对象的最大大小。

Default: 100

GRAPHENE = {
    'RELAY_CONNECTION_MAX_LIMIT': 100,
}

CAMELCASE_ERRORS

When set to True field names in the errors object will be camel case. By default they will be snake case.

当设置为True时,errors对象中的字段名将为大小写。默认情况下,它们将是蛇型命名法[驼峰命名法]。

Default: False

GRAPHENE = {
   'CAMELCASE_ERRORS': False,
}

# result = schema.execute(...)
print(result.errors)
# [
#     {
#         'field': 'test_field',
#         'messages': ['This field is required.'],
#     }
# ]
GRAPHENE = {
   'CAMELCASE_ERRORS': True,
}

# result = schema.execute(...)
print(result.errors)
# [
#     {
#         'field': 'testField',
#         'messages': ['This field is required.'],
#     }
# ]

DJANGO_CHOICE_FIELD_ENUM_V3_NAMING

Set to True to use the new naming format for the auto generated Enum types from Django choice fields. The new format looks like this: {app_label}{object_name}{field_name}Choices

设置为“True”以对从Django选项字段自动生成的枚举类型使用新的命名格式。新的格式如下:{app_label}{object_name}{field_name}Choices

Default: False

DJANGO_CHOICE_FIELD_ENUM_CUSTOM_NAME

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.

定义接受Django选项字段并返回字符串以完全自定义枚举类型命名的函数的路径。

If set to a function then the DJANGO_CHOICE_FIELD_ENUM_V3_NAMING setting is ignored.

如果设置为函数,则忽略DJANGO_CHOICE_FIELD_ENUM_V3_NAMING设置。

Default: None

# 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"
}

SUBSCRIPTION_PATH

Define an alternative URL path where subscription operations should be routed.

定义应路由订阅操作的备用URL路径。

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).

GraphiQL接口将使用此设置智能地路由订阅操作。如果您有更高级的基础结构要求,以防止在同一路径上处理websocket(例如,在/graphql上侦听的WSGI服务器和在/ws/graphql侦听的ASGI服务器),那么这很有用。

Default: None

GRAPHENE = {
   'SUBSCRIPTION_PATH': "/ws/graphql"
}

GRAPHIQL_HEADER_EDITOR_ENABLED

GraphiQL starting from version 1.0.0 allows setting custom headers in similar fashion to query variables.

从版本1.0.0开始的GraphiQL允许以类似于查询变量的方式设置自定义头。

Set to False if you want to disable GraphiQL headers editor tab for some reason.

如果出于某种原因要禁用GraphiQL头编辑器选项卡,请设置为False

This setting is passed to headerEditorEnabled GraphiQL options, for details refer to GraphiQLDocs.

此设置传递给“headerEditorEnabled”GraphiQL选项,有关详细信息,请参阅GraphiQLDocs.

Default: True

GRAPHENE = {
   'GRAPHIQL_HEADER_EDITOR_ENABLED': True,
}
posted @ 2020-09-25 07:17  双葫  阅读(465)  评论(0编辑  收藏  举报