首页 > 解决方案 > 使用石墨烯返回在 Graphql 中插入字符串的字典

问题描述

我希望我的 graphql 查询以字典的形式返回多个值,但我只能在字符串中返回字典。 在此处输入图像描述

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

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

标签: graphqlgraphene-python

解决方案


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

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

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

推荐阅读