我收到此错误:
"errors": [
{
"message": "Type Query must define one or more fields."
}
]
当我运行查询时:
{
user{
_id
name
username
password
email
date_inscription
profession
}
}
答案 0 :(得分:0)
此错误表示您的查询未返回任何字段。确保在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
}