Graphql,如何返回空数组而不是空数组
我是Graphql新手,我想知道是否有方法返回空数组而不是关系中的null。 让我们选择一个典型的用户和帖子示例Graphql,如何返回空数组而不是空数组,graphql,Graphql,我是Graphql新手,我想知道是否有方法返回空数组而不是关系中的null。 让我们选择一个典型的用户和帖子示例 type User { id: ID! posts: [Post] } Type Post { id: ID! comment: String! } 当我对一个没有任何帖子的用户进行查询时,我希望posts属性上有一个空数组,但现在我得到了null,我该怎么做呢? 提前感谢。这需要在GraphQL模式中完成(而不是在GraphQL查询中)-GraphQL字段解析器
type User {
id: ID!
posts: [Post]
}
Type Post {
id: ID!
comment: String!
}
当我对一个没有任何帖子的用户进行查询时,我希望posts属性上有一个空数组,但现在我得到了null
,我该怎么做呢?
提前感谢。这需要在GraphQL模式中完成(而不是在GraphQL查询中)-GraphQL字段解析器应该返回数组而不是null,并且(可选)指定它返回的数组为非null;例如:
const typeDefs=gql`
类型用户{
id:id!
波斯特:[波斯特!
}
`;
常量解析程序={
用户:{
posts(用户,_args,{getPosts}){
return(wait getPosts({user_id:user.id}))|[];
}
}
}
使用哪种服务器实现语言?