D
D
DeniSidorenko2021-04-06 11:56:13
Node.js
DeniSidorenko, 2021-04-06 11:56:13

Why does Graphql return undefined if everything in console.log has data?

Good afternoon, there is a Resolver in which there is a Query. It is required to search for a restaurant by id
and if, for example, we insert such a code, everything works fine

Restaurant: async(parent, args) => {
      return await Restaurant.findOne({_id: args.id})
    }


However, if I add the populate and execPopulate methods, I get undefined on the front
Restaurant: async(parent, args) => {
      const items = await Restaurant.findOne({_id: args.id})
      const populatedItems = await items.populate('kinds').execPopulate()
      return populatedItems
    }

If you do console.log(populatedItems) there is an object with the necessary data, and the populate method worked just as well. as far as I noticed from more than 2 hours of testing, GraphqL stops working when the populate method comes into play

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DeniSidorenko, 2021-04-06
@DeniSidorenko

I found an error, the fact is that in Type I determined that I only get ID and therefore when I received the kinds object instead of id there was an error. It was necessary to fix in Type and query

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question