如何解决GraphQL 中的 Upsert 涉及分层数据
我有以下结构,包含 3 个表之间的层次关系。 id 列是每个表中的主键。
Grandparent - id,name
|
|__ Parent - id,name,GrandparentID (i.e. Foreign key to Grandparent.id column)
|
|__ Child - id,ParentID (i.e. Foreign key to Parent.id column)
使用 upsert
解析器(即自动生成),我想在所有 3 个表中创建/更新条目。
我试过下面的 upsert 查询。
mutation upsertGrandparent
($updateData : GrandparentUpdateInput!,$createData : GrandparentCreateInput!,$where : GrandparentCreateWhereUniqueInput!
){
upsertGrandparent(
update : $updateData,create :$createData
where: $where
)
{
name
}
}
{
"createData": {
"name": "Grandparent_01","Parent": {
"create": {
"name": "Parent_01","Child" : {
"create": {
"name": "Child_01"
}
}
}
}
},"updateData": {
"name": {"set": "Grandparent_02"},"Parent": {
"updateMany": {
"data": {"name": { "set": "Parent_02" }},"where": {"name": { "gt": "zzzz"}},"Child" : {
"updateMany": {
"data": {"name": { "set": "Child_02" }},}
}
}
}
},"where": {
"id": "30"
}
}
使用上面的 upsert 查询,我可以同时在所有 3 个表中创建条目。
但是,在更新的情况下,如果它在 Grandparent
表中找到匹配的行,即使为表 Parent
和 Child
提供了新条目,它也只会对所有 3 个表执行更新。>
我想实现一个场景,对于 1 个祖父母,父表中可以存在多个条目,类似地,在 1 个父表下,子表中可以存在多个条目。在祖父母表中创建条目后,我应该能够稍后在现有祖父母条目下使用 upsert 突变在表 Parent 和 Children 中创建条目。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。