【问题标题】:Returning String or [String] in Appsync schema在 Appsync 架构中返回 String 或 [String]
【发布时间】:2021-11-04 14:33:18
【问题描述】:

我正在寻找这个问题的答案,似乎其他人也有,但我在任何地方都找不到明确的答案 (Appsync query union return type throws 400)

我有一个 GraphlQL 类型,它的属性可以返回字符串或字符串数​​组,就像这样。

type Button {
   color: String | [String]
}

有没有办法使用 Appsync 来完成这项工作?我尝试过使用 Union,但收到 400 错误

type ColorSingle {
   color: String
}

type ColorMulti {
   color: [String]
}

union Colors = ColorSingle | ColorMulti

type Button {
   color: Colors
}

和查询:

getSource(sourceId: "company") {
   themeConfig {
     component {
        ...on ColorSingle {
           __typename
           color
       }
       ...on ColorMulti {
           __typename
           color
       }
    }
  }
}

【问题讨论】:

    标签: graphql aws-appsync aws-serverless


    【解决方案1】:

    希望在这里提供帮助还为时不晚...我之前在响应中未提供 __typename 时得到了 400。 AWS 文档 - https://docs.aws.amazon.com/appsync/latest/devguide/interfaces-and-unions.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-12-28
      • 2016-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-11-27
      • 1970-01-01
      相关资源
      最近更新 更多