GraphQLUnion与GraphQLList
我的解析器可以返回PostType的列表或ErrorType。但是,我似乎无法用GraphQL描述这种情况:GraphQLUnion与GraphQLList,graphql,graphql-js,Graphql,Graphql Js,我的解析器可以返回PostType的列表或ErrorType。但是,我似乎无法用GraphQL描述这种情况: const PostGetAllResponseType: GraphQLUnionType = new GraphQLUnionType({ name: 'PostGetAllResponse', types: [GraphQLList(PostType), ErrorType], resolveType(value) { if (_.isArray(value))
const PostGetAllResponseType: GraphQLUnionType = new GraphQLUnionType({
name: 'PostGetAllResponse',
types: [GraphQLList(PostType), ErrorType],
resolveType(value) {
if (_.isArray(value)) {
return GraphQLList(PostType)
}
return ErrorType
},
})
我如何定义一个GraphQLUnion,其中一个类型是GraphQLList,另一个类型不是(列表)?你不能,一个union的成员必须是对象类型,而不是包装类型(列表和非null都是包装类型)。这太可惜了。您可能希望列表是第一类类型。。。