【问题标题】:Upsert Graphql Mutation with conflict constraint on nested object在嵌套对象上具有冲突约束的 Upsert Graphql Mutation
【发布时间】:2020-11-06 05:52:20
【问题描述】:

我正在尝试在单个突变中进行 upsert。这里我有两个表Users表[id,isVerified,type]和Customers表[id,name,deviceToken] 这里Customers.id是Users.Id的外键。
以下是突变-

 MyMutation {
  insert_Users(objects: [{isVerified: false, name: "+9100000000", type: "customer", 
    Customers: {data: {deviceToken: "TestToken001"}}}],
      on_conflict: {
            constraint: Users_name_key,
            update_columns: [isVerified]
          }) {
    affected_rows
    returning {
      Customers{
        deviceToken
      }
  }
}
} ```

//But when I run this, I get the exception 

{
  "errors": [
    {
      "extensions": {
        "path": "$.selectionSet.insert_Users.args.objects[0].Customers.data",
        "code": "constraint-violation"
      },
      "message": "Uniqueness violation. duplicate key value violates unique constraint \"Customers_pkey\""
    }
  ]
}

这似乎是因为我没有在嵌套的客户对象上设置冲突约束。如何为嵌套对象添加冲突约束?

【问题讨论】:

    标签: graphql mutation hasura


    【解决方案1】:

    您还需要在嵌套数据中添加约束对象。 比如:

    MyMutation {
      insert_Users(objects: [{isVerified: false, name: "+9100000000", type: "customer", 
        Customers: {
           data: {deviceToken: "TestToken001"}, 
           on_conflict: {
                constraint: Customers_pkey,
                update_columns: [deviceToken]
              }         
         }}],
          on_conflict: {
                constraint: Users_name_key,
                update_columns: [isVerified]
              }) {
        affected_rows
        returning {
          Customers{
            deviceToken
          }
      }
    }
    } 
    

    【讨论】:

      猜你喜欢
      • 2021-05-08
      • 2021-12-01
      • 1970-01-01
      • 2020-04-05
      • 2019-07-31
      • 2011-01-31
      • 1970-01-01
      • 1970-01-01
      • 2023-03-12
      相关资源
      最近更新 更多