1

I have this problem where when i run any rootquery that is taking data from the database (mongodb) every field of the response is null

I've tried with predefined hardcoded json and it worked for it but when i put mongoose promise in the resolve it returns null in every field of the response When adding the query to the database trough mutations and returning the data i can see added info i also can see it when i run a promise and console log the output from the Book.find({}) in the resolve

Part of the rootquery that defines the query

    books: {
            type: BookType,
            resolve(parent, args) {
                return Book.find({})
            }
        }

GraphQL Type

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
})

My query

{
    templates {
      name
      genre
      authorid
    }
}

This is what i get for the response

{
  "data": {
    "books": {
      "name": null,
      "genre": null,
      "authorid": null
    }
  }
}

I should see the data from the database as i have some entries in it

Vadlord
  • 11
  • 2

0 Answers0