【问题标题】:Sequelize on GraphQL update not return anythingSequelize on GraphQL update 不返回任何内容
【发布时间】:2017-04-26 21:10:49
【问题描述】:

GraphQL 使用 Sequelize 更新返回 null。

updatePerson: {
  type: Person,
  args: {
    value: {
      type: UpdatePersonInputType
    },
    where: {
      type: WhereUpdatePersonInputType
    }
  },
  resolve(_, args) {
    return Db.models.persons.update( args.value, {
      where: args.where
    });
  }
},

这是我使用 GraphiQL 的请求

mutation {
  updatePerson(value: {firstName: "John", lastName: "Doe", email: "johndoe@example.com"}, where: {id: 1}){
    id
    firstName
    lastName
    email
  }
}

这就是结果

{
  "data": {
    "updatePerson": {
      "id": null,
      "firstName": null,
      "lastName": null,
      "email": null
    }
  }
}

也许我在使用 Sequelize 更新时会出错。谁能解释发生了什么?

【问题讨论】:

标签: javascript sequelize.js graphql graphql-js


【解决方案1】:

不好意思,我用的是MySQLSequelize只支持PostgreSQL如果你需要返回affectedRows,但是如果你使用MySQL 你只能返回affectedCount

http://docs.sequelizejs.com/en/latest/api/model/#updatevalues-options-promisearrayaffectedcount-affectedrows

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-03-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-04-27
    • 2019-04-06
    • 2012-02-15
    相关资源
    最近更新 更多