GraphQL:查询:无法从MongoDb获取数据

时间:2018-08-31 10:09:46

标签: javascript mongodb express-graphql

我收到此错误:

"errors": [
    {
      "message": "Type Query must define one or more fields."
    }
  ]

当我运行查询时:

{
  user{

   _id 
    name
    username
    password
    email
    date_inscription
    profession

  }
}

我有同样的例子  https://blog.cloudboost.io/a-crud-app-with-apollo-graphql-nodejs-express-mongodb-angular5-2874111cd6a5

1 个答案:

答案 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
}