【问题标题】:After migrating to pure websocket, I get a GraphQL subscription error on AWS Appsync迁移到纯 websocket 后,我​​在 AWS Appsync 上收到 GraphQL 订阅错误
【发布时间】:2021-11-14 11:33:42
【问题描述】:

由于最近的一些 AWS 限制,在 Appsync 上使用 GraphQL 订阅时,我不能再使用 MQTT over Websockets。 基于this link from 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>}
}

我完全不清楚的是,我在切换到纯 websockets 后开始遇到这个问题。

我已经比较了纯 websockets 和 MQTT 之间的 Cloudwatch 日志,但我没有发现任何相关差异,除了请求 ID 和计时日志。

哦,忘了说我用的是OIDC认证方式。

代码库可用here。 谢谢,

【问题讨论】:

    标签: python websocket graphql aws-appsync


    【解决方案1】:

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

    因此,新的Command 对象如下:

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

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

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

    【讨论】:

      猜你喜欢
      • 2020-11-01
      • 2019-09-16
      • 2021-07-14
      • 1970-01-01
      • 2022-08-07
      • 2022-08-17
      • 2018-08-24
      • 1970-01-01
      • 2021-03-11
      相关资源
      最近更新 更多