嵌套对象的 Hasura GraphQL UPSERT 突变
Hasura GraphQL UPSERT mutation for nested objects
所以我正在尝试使用变量为 inserting/updating 构造一个“人”的记录及其地址、电子邮件、电话信息到多个表中的突变。
mutation insertPerson ($address: [adr_insert_input!]!, $emails: [emails_insert_input!]!) {
insert_info(objects: [{
f_name: "User1",
l_name: "Test"
address: {
data: $address,
on_conflict: {
constraint: person_id_pk,
update_column: [add_text_line1, zip_code]
}
},
emails: {
data: $emails,
on_conflict: {
constraint: person_id_pk,
update_column: [email_text]
}
}
}], on_conflict: {
constraints: person_pk,
update_columns: [f_name, l_name]
}) {
affected_rows
}
}
我的变量设置如下...
{
"address": [{
"add_text_line1": "123 Main Street",
"zip_code": 50501
}],
"emails": [{
"email_text": "FirstLastName@email.com"
}]
}
这 按我的预期工作 (电子邮件数组中也有多个值),但我需要移动 f_name 和 l_name 值(整个 Person 对象)也转换为变量。我该如何实现?
我以这种方式尝试了以下突变,但这导致了两个单独的插入和传递的空值...
mutation insertPerson ($person: person_insert_input!, $address: [adr_insert_input!]!){
insertData(objects: [
$person,
{
address: { data: $address }
}
]) { affected_rows }
}
这导致了两个单独的插入...第一个地址为空的人,然后地址为空的人。
如何在将个人信息用作变量的一部分时获得第一个突变的结果不将其硬编码到查询本身?
谢谢!
您需要将 insert_info 个对象作为变量传递
mutation insertPerson ($info_objects: [insert_info_insert_input!]!) {
insert_info(objects: $info_objects, on_conflict: {
constraints: person_pk,
update_columns: [f_name, l_name]
}) {
affected_rows
}
}
并且您的变量将是 info_objects
的数组
{info_objects: [{
f_name: "User1",
l_name: "Test"
address: {data: [{
"add_text_line1": "123 Main Street",
"zip_code": 50501
}]},
on_conflict: {
constraint: person_id_pk,
update_column: [add_text_line1, zip_code]
}
},
emails: {
data: [{
email_text: "FirstLastName@email.com"
}],
on_conflict: {
constraint: person_id_pk,
update_column: [email_text]
}
}
}]}
所以我正在尝试使用变量为 inserting/updating 构造一个“人”的记录及其地址、电子邮件、电话信息到多个表中的突变。
mutation insertPerson ($address: [adr_insert_input!]!, $emails: [emails_insert_input!]!) {
insert_info(objects: [{
f_name: "User1",
l_name: "Test"
address: {
data: $address,
on_conflict: {
constraint: person_id_pk,
update_column: [add_text_line1, zip_code]
}
},
emails: {
data: $emails,
on_conflict: {
constraint: person_id_pk,
update_column: [email_text]
}
}
}], on_conflict: {
constraints: person_pk,
update_columns: [f_name, l_name]
}) {
affected_rows
}
}
我的变量设置如下...
{
"address": [{
"add_text_line1": "123 Main Street",
"zip_code": 50501
}],
"emails": [{
"email_text": "FirstLastName@email.com"
}]
}
这 按我的预期工作 (电子邮件数组中也有多个值),但我需要移动 f_name 和 l_name 值(整个 Person 对象)也转换为变量。我该如何实现?
我以这种方式尝试了以下突变,但这导致了两个单独的插入和传递的空值...
mutation insertPerson ($person: person_insert_input!, $address: [adr_insert_input!]!){
insertData(objects: [
$person,
{
address: { data: $address }
}
]) { affected_rows }
}
这导致了两个单独的插入...第一个地址为空的人,然后地址为空的人。
如何在将个人信息用作变量的一部分时获得第一个突变的结果不将其硬编码到查询本身?
谢谢!
您需要将 insert_info 个对象作为变量传递
mutation insertPerson ($info_objects: [insert_info_insert_input!]!) {
insert_info(objects: $info_objects, on_conflict: {
constraints: person_pk,
update_columns: [f_name, l_name]
}) {
affected_rows
}
}
并且您的变量将是 info_objects
的数组{info_objects: [{
f_name: "User1",
l_name: "Test"
address: {data: [{
"add_text_line1": "123 Main Street",
"zip_code": 50501
}]},
on_conflict: {
constraint: person_id_pk,
update_column: [add_text_line1, zip_code]
}
},
emails: {
data: [{
email_text: "FirstLastName@email.com"
}],
on_conflict: {
constraint: person_id_pk,
update_column: [email_text]
}
}
}]}