GraphQLUnion 与 GraphQLList

GraphQLUnion with GraphQLList

我的解析器可以 return PostType 列表或 ErrorType。然而,我似乎无法用 GraphQL 来描述这个场景:

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

    return ErrorType
  },
})

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

不可以,union的成员必须是object类型,不能是wrapping类型(list和non-null都是wrapping类型)