Django GraphQL文档资源管理器编码

时间:2019-07-19 19:57:46

标签: django encoding graphql

我对GraphQL文档浏览器有问题。正如您在图片上所看到的,它存在俄语文本问题,它显示了一些经过两次编码的字符串,例如“ \\ u041c \\ u043e \\ u0441”。该如何解决?

enter image description here

已添加:

现在我做了一个这样的补丁(请参阅.replace('\\\\', '\\')部分)

from graphql.type import introspection

def resolver(input_val, *_):
    if input_val.default_value is None:
        return None
    if isinstance(input_val.default_value, str):
        return introspection.print_ast(introspection.ast_from_value(input_val.default_value, input_val)).replace('\\\\', '\\')
    return introspection.print_ast(introspection.ast_from_value(input_val.default_value, input_val))

introspection.__InputValue = introspection.GraphQLObjectType(
    "__InputValue",
    description="Arguments provided to Fields or Directives and the input fields of an "
    "InputObject are represented as Input Values which describe their type "
    "and optionally a default value.",
    fields=lambda: introspection.OrderedDict(
        [
            ("name", introspection.GraphQLField(introspection.GraphQLNonNull(introspection.GraphQLString))),
            ("description", introspection.GraphQLField(introspection.GraphQLString)),
            ("type", introspection.GraphQLField(introspection.GraphQLNonNull(introspection.__Type))),
            (
                "defaultValue",
                introspection.GraphQLField(
                    type=introspection.GraphQLString,
                    resolver=resolver,
                ),
            ),
        ]
    ),
)

0 个答案:

没有答案