javascript - GraphQL:查询:无法从 MongoDb 获取数据
问题描述
我收到此错误:
"errors": [
{
"message": "Type Query must define one or more fields."
}
]
当我运行查询时:
{
user{
_id
name
username
password
email
date_inscription
profession
}
}
解决方案
此错误表明您的查询未返回任何字段。确保在 graphql/queries/user/user.js 下至少定义了一个字段,如下所示:
const UserListType = new GraphQLObjectType({
name: 'UserList',
fields() {
return {
id: {
type: GraphQLInt,
description: "Unique identifier of the User"
}
}
}
})
要检查的另一部分是您已正确导出 graphql/queries/index.js 中的查询,如下所示:
// Users
const listUsers = require('./user/listUsers')
module.exports = {
// Users
listUsers
}
推荐阅读
- python - 在 matplotlib 中为检查按钮文本着色
- mysql - Hibernate 返回最后一行 n 次
- robotframework - 已超出启动关键字的最大限制
- google-cloud-platform - 删除 gcs 冗余 gcs 存储桶
- javascript - 如何在javascript文件中提取数据库内容
- python - 如何在Python中获取包含多个单词的所有句子
- macos - macOS 上的多个网络扩展
- javascript - 无论如何我可以重构它以使用过滤器等数组函数
- statistics - 计算对数正态分布置信区间的修正 Cox 方法
- nestjs - 如何使用 Faker 库生成 ISO 3166-1 alpha-3 国家代码?