【问题标题】:GraphQLUnion with GraphQLListGraphQLUnion 与 GraphQLList
【发布时间】:2021-01-01 00:07:46
【问题描述】:

我的解析器可以返回 PostType 列表或 ErrorType。但是,我似乎无法在 GraphQL 中描述这种场景:

const PostGetAllResponseType: GraphQLUnionType = new GraphQLUnionType({
  name: 'PostGetAllResponse',
  types: [GraphQLList(PostType), ErrorType],
  resolveType(value) {
    if (_.isArray(value)) {
      return GraphQLList(PostType)
    }

    return ErrorType
  },
})

如何定义一个类型是 GraphQLList 而另一种类型不是(列表)的 GraphQLUnion?

【问题讨论】:

    标签: graphql graphql-js


    【解决方案1】:

    你不能,联合的成员必须是对象类型而不是包装类型(列表和非空都是包装类型)。

    【讨论】:

    • 真可惜。您会期望列表是一流的类型...
    猜你喜欢
    • 2016-07-13
    • 2020-05-27
    • 2021-05-28
    • 2016-12-04
    • 2016-08-17
    • 2018-07-31
    • 2017-04-30
    • 2019-08-02
    • 2018-09-23
    相关资源
    最近更新 更多