【问题标题】:Return dictionary insted of string in Graphql using graphene使用石墨烯在 Graphql 中返回字典而不是字符串
【发布时间】:2020-03-23 18:20:52
【问题描述】:

我希望我的 graphql 查询以字典的形式返回多个值,但我只能在字符串中返回字典。 enter image description here

class Query(ObjectType):

get_reply = String(
    question=String(),
    sender=String(),
    timestamp=String()
)

def resolve_get_reply(root, info, question, sender, timestamp):
    written_to_database = False
    reply = 'hello'
    d = {"reply": reply, "wtd": written_to_database}
    return d

现有的指南让我更加困惑。 我如何为这种情况定义架构?

【问题讨论】:

    标签: graphql graphene-python


    【解决方案1】:

    您已将 get_reply 变量设置为字符串。因此,您将收到一个字符串作为响应。

    您可以创建一个自定义回复类并设置 get_reply 如下:

    get_reply = graphene.Field(Reply, 
        question=String()
    )
    

    【讨论】:

    • 谢谢你,我按照你说的做了,为回复添加了一个模式,一切都很顺利
    猜你喜欢
    • 2020-11-25
    • 2018-03-06
    • 2017-05-11
    • 2017-05-13
    • 2020-01-27
    • 2020-07-27
    • 2020-05-23
    • 1970-01-01
    • 2022-10-18
    相关资源
    最近更新 更多