[英]How to map a list in a graphql mutation query
What the list object looks like列表对象的样子
What the Retool table looks like Retool 表的外观
I am creating a Retool dashboard and allowing a user to edit rows of an organization table and once the user makes changes I would like to update the database with a Graphql mutation query.我正在创建一个 Retool 仪表板并允许用户编辑组织表的行,一旦用户进行更改,我想使用 Graphql 突变查询更新数据库。
I am trying to map this array (2 rows were edited in this case) in a mutation query to update my database for these two organizations only.我试图在突变查询中映射这个数组(在这种情况下编辑了 2 行),以便仅为这两个组织更新我的数据库。
So far I have tried something like this but I keep on getting an error that this is not a valid Graphql query.到目前为止,我已经尝试过这样的事情,但我不断收到一个错误,即这不是有效的 Graphql 查询。
mutation edit_org_details {
{{
orgs_table.recordUpdates.map(updates => (`\n
update_orgs_by_pk(\n
_set: {\n
name: "${updates.name}",\n
legal_entity_name: "${updates.legal_entity_name}",\n
industry: "${updates.industry}",\n
country: "${updates.country}",\n
status: "${updates.status}" \n
},\n
pk_columns: {\n
id: "${updates.id}"\n
} { \n
name \n
})\n`)
)
}}
}
The update_orgs_by_pk query is fine as it works on hasura when I tried using info to mutate one organization, but I can't seem to figure out how to map a list and do multiple mutations. update_orgs_by_pk 查询很好,因为当我尝试使用 info 来改变一个组织时,它可以在 hasura 上运行,但我似乎无法弄清楚如何映射一个列表并进行多个突变。
Actually, what you are looking for is Retool - MongoDB bulkWrite query, I am using this approach to update edited records from table component.实际上,您正在寻找的是 Retool - MongoDB bulkWrite 查询,我正在使用这种方法来更新表组件中的已编辑记录。
My handler, (bulkUpdateHandler)我的处理程序,(bulkUpdateHandler)
if (myTable?.recordUpdates.length == 0) return;
let records = myTable?.recordUpdates?.map((r) => ({
updateOne: {
"filter": {
"_id": {
$oid: r._id
}
},
"update": {
$set: {
"name": r.name,
"year": r.year,
"month": r.month,
"day": r.day
}
}
}
}));
return records;
Resource query ,资源查询,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.