amazon-web-services - 如何在 GraphQL 中正确地使用参数进行订阅?
问题描述
在AWS AppSync中,我尝试测试我的GraphQL架构。我有点困惑,需要帮助。当有争论时,我的订阅watchMessages
不起作用。如果我从模式中删除参数并对其进行测试,它就可以工作。但我只需要接收来自特定房间的消息。我错过了什么?
input CreateMessageInput {
roomId: String!
messageText: String
messageAuthor: String
}
type CreateMessageOutput {
messageId: String!
messageCreatedDateTime: String!
messageText: String!
messageAuthor: String
}
type Mutation {
createMessage(input: CreateMessageInput): CreateMessageOutput
}
type Subscription {
watchMessages(roomId: String!): CreateMessageOutput
@aws_subscribe(mutations: ["createMessage"])
}
我做了这样的订阅查询:
subscription MySubscription {
watchMessages(roomId: "5d354323") {
messageId
messageCreatedDateTime
messageText
messageAuthor
}
}
我做了这样的突变查询:
mutation MyMutation {
createMessage(input: {roomId: "5d354323", messageAuthor: "Bob", messageText: "Hello!"}) {
messageId
messageCreatedDateTime
messageText
messageAuthor
}
}
解决方案
最后,我找到了解决方案。所有订阅参数都必须作为返回类型中的字段存在。这意味着参数的类型也必须与返回对象中的字段类型相匹配。我roomId
在类型中添加了字段CreateMessageOutput
。
type CreateMessageOutput {
roomId: String!
messageId: String!
messageCreatedDateTime: String!
messageText: String!
messageAuthor: String
}
推荐阅读
- selenium - selenium.common.exceptions.NoSuchElementException:消息:使用 Selenium Python 在 Twitter 中向电子邮件字段发送文本时无法定位元素错误
- r - R:仅从街道名称、城市和州获取邮政编码
- django - 我怎样才能找到用户总数?
- c# - 显示二维数组行列计数器
- javascript - 无法解构“未定义”的属性“纬度”
- generics - 使用@CompileStatic 和泛型类时,构造函数不能应用于“(T)”错误
- python - 当 recycleview 中的 viewclass 按钮被按下时如何移动到下一个屏幕,该按钮在 kivy 的屏幕上?
- python - 导入自己的数据,如 MNIST 或 CIFAR10 load_data()
- c++ - 我们可以在不知道其真实类型的情况下将基类指针转换为派生类指针吗?
- asp.net - 将浏览器 PDF 保存到磁盘