使用石墨烯返回在Graphql中由字符串插入的字典

时间:2019-11-28 06:34:43

标签: graphql graphene-python

我希望我的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

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

1 个答案:

答案 0 :(得分:2)

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

您可以创建一个自定义的Reply类并按如下所示设置get_reply:

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