我从数据库传来的graphql中的resolve返回的每个字段都为空

我有一个问题,当我运行从数据库(mongodb)获取数据的任何rootquery时,响应的每个字段都为空

我已经尝试过使用预定义的硬编码json并对其起作用,但是当我在解析中放入猫鼬诺言时,它在响应的每个字段中都返回null 当将查询添加到数据库槽中的突变并返回数据时,我可以看到添加的信息,当我运行诺言并在解决方案中控制台记录Log.Bookp.find({})的输出时,也可以看到它

定义查询的rootquery的一部分

    books: {
            type: BookType,resolve(parent,args) {
                return Book.find({})
            }
        }

GraphQL类型

const BookType= new GraphQLObjectType({
    name: 'BookType',fields: () => ({
        _id: {type: GraphQLID},name: {type: GraphQLString},genre: {type: GraphQLString},authorid: {type: GraphQLString}
    })
});

const bookSchema = new mongoose.Schema({
    name: String,genre: String,authorid: String
})

我的查询

{
    templates {
      name
      genre
      authorid
    }
}

这就是我得到的回应

{
  "data": {
    "books": {
      "name": null,"genre": null,"authorid": null
    }
  }
}

我应该看到数据库中的数据,因为其中有一些条目

zxcvbnmasdfghjkl1236 回答:我从数据库传来的graphql中的resolve返回的每个字段都为空

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3164753.html

大家都在问