首页 > 解决方案 > 迁移到纯 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认证方式。

代码库可在此处获得。谢谢,

标签: pythonwebsocketgraphqlaws-appsync

解决方案


最后,我删除了对象的非空要求Command

结果,新Command对象如下:

type Command {
    commandId: ID
    createdAt: AWSDateTime
    command: String
    arguments: [String]
    deviceId: ID
    status: Int
}

这不是一种解决方案,而是一种解决方法。

欢迎任何更体面的解决方案。


推荐阅读