python - 迁移到纯 websocket 后,我在 AWS Appsync 上收到 GraphQL 订阅错误
问题描述
由于最近的一些 AWS 限制,在 Appsync 上使用 GraphQL 订阅时,我不能再使用 MQTT over Websockets。基于来自 AWS 的这个链接,我更改了我的 Python 代码库。
它似乎连接正确,但是在订阅时,我收到以下错误:
{'message': "Cannot return null for non-nullable type: 'ID' within parent 'Command' (/onCommandCreated/commandId)"}
对象的每个字段都会重复此错误Command
。
这是架构:
type Command {
commandId: ID!
createdAt: AWSDateTime!
command: String!
arguments: [String]!
deviceId: ID!
status: Int!
}
type Mutation {
submitCommand(command: NewCommand!): Command
}
input NewCommand {
command: String!
arguments: [String]!
deviceId: ID!
}
type Subscription {
onCommandCreated(deviceId: ID!): Command
@aws_subscribe(mutations: ["submitCommand"])
}
schema {
mutation: Mutation
subscription: Subscription
}
这是我的订阅:
{
"query": """subscription onCommand($deviceId: ID!) {
onCommandCreated(deviceId: $deviceId) {
commandId
deviceId
command
arguments
status
}
}
""",
"variables": {"deviceId": <a device id>}
}
我绝对不清楚的是,在切换到纯 websocket 后我开始遇到这个问题。
我已经比较了纯 websockets 和 MQTT 之间的 Cloudwatch 日志,但我没有注意到任何相关差异,除了请求 ID 和计时日志。
哦,忘了说我用的是OIDC认证方式。
代码库可在此处获得。谢谢,
解决方案
最后,我删除了对象的非空要求Command
。
结果,新Command
对象如下:
type Command {
commandId: ID
createdAt: AWSDateTime
command: String
arguments: [String]
deviceId: ID
status: Int
}
这不是一种解决方案,而是一种解决方法。
欢迎任何更体面的解决方案。
推荐阅读
- python - 如何将张量从 import tensorflow.compat.v1 as tf 转换为 numpy 数组?
- javascript - 在 ReactJs 中没有显示变化反射的状态
- java - AEM 不会将新代码部署到作者服务器
- javascript - Google Sheets + Apps 脚本:仅当工作表中的列包含与 getElementById('item1') 中的单词匹配时才创建数据列表
- react-native - 如何在本机反应中显示列表中的多个选定项目
- reactjs - 使用 EXPO 保存到相机胶卷
- java - 在 Java 中读取 Excel 文件列
- python - 是否有更有效的方法来更新字典中每个键中所有子字段的值
- javascript - MongoDB 对象类型未保存
- php - 如何在“foreach”循环PHP中选择特定项目