Upsert Graphql Mutation 对嵌套对象有冲突约束
Upsert Graphql Mutation with conflict constraint on nested object
我正在尝试在单个突变中进行更新插入。这里我有两个 tables Users table [id,isVerified,type] 和 Customers table [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\""
}
]
}
这似乎是因为我没有在嵌套的客户对象上设置冲突约束。如何为嵌套对象添加冲突约束?
您还需要在嵌套数据中添加约束对象。
类似于:
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
}
}
}
}
我正在尝试在单个突变中进行更新插入。这里我有两个 tables Users table [id,isVerified,type] 和 Customers table [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\""
}
]
}
这似乎是因为我没有在嵌套的客户对象上设置冲突约束。如何为嵌套对象添加冲突约束?
您还需要在嵌套数据中添加约束对象。 类似于:
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
}
}
}
}