Py学习  »  Django

Django GraphQL文档资源管理器编码

user2626972 • 4 年前 • 272 次点击  

我对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,
                ),
            ),
        ]
    ),
)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/52489
 
272 次点击