简体   繁体   English

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

[英]GraphQL : queries : cannot get data from MongoDb

I get this error : 我收到此错误:

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

when I run my query : 当我运行查询时:

{
  user{

   _id 
    name
    username
    password
    email
    date_inscription
    profession

  }
}

I have the same example then https://blog.cloudboost.io/a-crud-app-with-apollo-graphql-nodejs-express-mongodb-angular5-2874111cd6a5 我有相同的示例,然后https://blog.cloudboost.io/a-crud-app-with-apollo-graphql-nodejs-express-mongodb-angular5-2874111cd6a5

This error indicates that your query doesn't return any fields. 此错误表明您的查询未返回任何字段。 Make sure that under graphql/queries/user/user.js you have at least one field defined like this: 确保在graphql / queries / user / user.js下,至少定义了一个如下所示的字段:

const UserListType = new GraphQLObjectType({ name: 'UserList', fields() { return { id: { type: GraphQLInt, description: "Unique identifier of the User" } } } })

The other piece to check is that you have properly exported the query in graphql/queries/index.js like this: 另一要检查的是,您已经像这样正确地将查询导出到了graphql / queries / index.js中:

// Users
const listUsers = require('./user/listUsers')

module.exports = {

  // Users
  listUsers
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM