graphql - 使用石墨烯返回在 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
现有的指南让我更加困惑。我如何为这种情况定义架构?
解决方案
您已将 get_reply 变量设置为字符串。因此,您将收到一个字符串作为响应。
您可以创建自定义回复类并设置 get_reply 如下:
get_reply = graphene.Field(Reply,
question=String()
)
推荐阅读
- go - 如何计算文件中的单词
- javascript - 无法从 API 正确获取数据
- angular - 当我使用括号表示法传递类型时,为什么复选框在 Angular 中不能按预期工作?
- list - 如何在 AppleScript 中的两个列表之间找到相等的值?
- c++ - 如何替换向量中的序列
- font-awesome - 为什么我有水瓶而不是字体真棒图标?
- javascript - 如何在 JavaScript 中正确使用 Promise.then()?
- c# - 如何从数据列表更新数据库表?
- python - 使用 Python 比较两个不同的 csv 列时无法获取缺失的元素
- android - 无法从资产中复制预先创建的数据库