Data null after saving entity with Moongose and GraphQL Data null after saving entity with Moongose and GraphQL mongoose mongoose

Data null after saving entity with Moongose and GraphQL


You're mixing Promises and callbacks. exec() will return a Promise, but only if doesn't have any arguments passed to it. Additionally, you need to return the Promise that's returned by exec().

return budget.save().then((res) => {  return Budget.findById(res._id) // missing return here    .populate('User')    .populate('Vehicle')    .exec() // don't need anything else})

You can clean this up a little more:

return budget.save()  .then(res => Budget.findById(res._id)    .populate('User')    .populate('Vehicle')    .exec())

If you need to transform the results returned by findById before turning them over to the client:

return budget.save()  .then(res => Budget.findById(res._id)    .populate('User')    .populate('Vehicle')    .exec())  .then(res => {    res.foo = 'Foo'    return res  })