javascript - 我在来自数据库的graphql中从resolve返回的每个字段都为null
问题描述
我有这个问题,当我运行任何从数据库(mongodb)获取数据的根查询时,响应的每个字段都是空的
我已经尝试使用预定义的硬编码 json 并且它适用于它但是当我将 mongoose 承诺放入解析中时,它在响应的每个字段中返回 null 当通过突变将查询添加到数据库并返回数据时,我可以看到添加的信息我当我运行一个promise并且控制台在resolve中记录Book.find({})的输出时也可以看到它
定义查询的根查询的一部分
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
}
}
}
我应该看到数据库中的数据,因为我有一些条目
解决方案
推荐阅读
- python - 如何解开熊猫数据框?
- r - 与 R 中的多个选项进行模式匹配
- python - tensorflow gpu 在“windows”上没有 docker 服务
- laravel - 将 Vue.js 安装到 Laravel 后无法加载示例组件
- javascript - 如何在 React 中使用 useState Hook 更改/添加数组的某一行的值
- postgresql - 在 PostgreSQL 中使用 Explain for Daterange 估计行数
- python - Python在iloc(或shift)中使用数据框列值
- go - 如何使用 Pion/Webrtc 将 VP8 帧间转换为图像?
- java - true 或 false 布尔表达式,何时放置 NOT 运算符?
- macos - ffmpeg 从 avi 文件生成无法播放的 MP4 文件