【问题标题】:Why mongoose saving raise error when using with GraphQL?与 GraphQL 一起使用时,为什么猫鼬保存会引发错误?
【发布时间】:2020-02-14 21:02:20
【问题描述】:

我添加了这个 GraphQL 解析器函数,

switchEventSellingStarted: async(_, {name, sellingStarted}) => {
      const e1 = Event.findOne({name: name})
      if (!e1) {
        throw new Error(`Couldn't find post with id ${name}`);
      }
      e1.sellingStarted = sellingStarted;
      await e1.save();
      return e1;
    }

在执行resolver时出现这个错误,为什么?

{
  "errors": [
    {
      "message": "e1.save is not a function", 

【问题讨论】:

    标签: mongoose graphql


    【解决方案1】:

    您在Event.findOne 前面缺少等待。没有它,e1 就是一个 Promise,并且 Promise 对象上没有名为 save 的方法。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-03-02
      • 2020-12-11
      • 2021-08-23
      • 1970-01-01
      • 2012-12-09
      • 1970-01-01
      • 2019-06-09
      • 2021-07-27
      相关资源
      最近更新 更多