【问题标题】:Cannot resolve a field name with underscores in graphene无法解析石墨烯中带下划线的字段名称
【发布时间】:2020-08-18 22:33:18
【问题描述】:

我浏览了 Python 石墨烯的 the documentation,它起作用了。这是代码-

from graphene import ObjectType, String, Schema


class Query(ObjectType):
    hello = String(name=String(default_value="stranger"))

    def resolve_hello(root, info, name):
        return f'Hello {name}!'


schema = Schema(query=Query)

query = '{ hello(name: "GraphQL") }'

result = schema.execute(query)

print(result.data['hello'])    # "Hello GraphQL!"

但是,将hello 更改为some_field,将resolve_hello 更改为resolve_some_field,并制作query = '{ some_field(name: "GraphQL" }' ,我得到的最终结果是None

有没有办法处理包含下划线的字段?

【问题讨论】:

    标签: python graphql graphene-python


    【解决方案1】:

    我不知道幕后的石墨烯是如何将蛇壳转化为骆驼壳的。

    架构定义中的一切都很完美,但我作为客户端调用它的方式需要更改。

    因此,而不是:

    query = '{ some_field(name: "GraphQL" }'

    ...我需要做的:

    query = '{ someField(name: "GraphQL" }'

    ...因为这是客户端 JavaScript 更愿意调用它的方式。

    【讨论】:

      猜你喜欢
      • 2018-10-16
      • 2019-04-03
      • 1970-01-01
      • 2018-04-07
      • 2021-03-14
      • 2020-08-11
      • 2020-04-22
      • 2017-05-13
      • 2017-05-11
      相关资源
      最近更新 更多