【问题标题】:id cannot be used in graphQL where clause?id 不能在 graphQL where 子句中使用?
【发布时间】:2018-02-10 07:28:51
【问题描述】:
{
  members {
    id
    lastName
  }
}

当我尝试从成员表中获取数据时,我可以得到以下响应。

{   "data": {
    "members": [
      {
        "id": "TWVtYmVyOjE=",
        "lastName": "temp"
      },
      {
        "id": "TWVtYmVyOjI=",
        "lastName": "temp2"
      }
    ]   } }

但是,当我尝试使用 'id' where 子句更新行时,控制台显示错误。

mutation {
    updateMembers(
      input: {
        values: {
          email: "testing@test.com"
        },
        where: {
          id: 3
        }
      }
    ) {
      affectedCount
      clientMutationId
    } 
}

"message": "'where 子句'中的未知列 'NaN'",

上面的一些结果让我很困惑。

  1. 为什么返回的id不是数值?从数据库中,它是一个数字。
  2. 当我更新记录时,我可以在 where 子句中使用数字 id 值吗?

我正在使用 nodejs,apollo-clientgraphql-sequelize-crud

【问题讨论】:

    标签: node.js sequelize.js graphql apollo


    【解决方案1】:

    TL;DR:在此处查看我可能与 relay 不兼容的 PR https://github.com/Glavin001/graphql-sequelize-crud/pull/30

    基本上,内部源代码是从relay-graphql 调用fromGlobalId API,但在其中传递了一个原始值(例如您的3),导致它返回undefined。因此,我只是从源代码中删除了调用并提出了拉取请求。

    附:这个用我 2 小时解决的 bug 构建失败,我认为这个解决方案可能不够一致。

    【讨论】:

      【解决方案2】:

      请试试这个

      mutation {
          updateMembers(
            input: {
              values: {
                email: "testing@test.com"
              },
              where: {
                id: "3"
              }
            }
          ) {
            affectedCount
            clientMutationId
          } 
      }
      

      【讨论】:

        猜你喜欢
        • 2022-09-27
        • 1970-01-01
        • 2017-01-15
        • 1970-01-01
        • 1970-01-01
        • 2021-05-05
        • 1970-01-01
        • 2020-07-28
        • 2018-10-01
        相关资源
        最近更新 更多