【发布时间】:2020-07-30 19:00:09
【问题描述】:
我想在同一个查询中运行多个突变。
在下面的示例中,我创建了一个订单,然后我创建了一个产品记录,与之前创建的有关。
我必须有 2 个突变。
首先,我插入一个订单。在输出中,我检索了 idorder 等。
然后,我插入一个产品。本产品
mutation {
createOrder(input: {
order: {
ordername: "My order"
}
}) {
order {
idorder
ordername
}
},
createProduct(input: {
product: {
quantity: 3
idrefproduct: 25 # link to refProduct
idorder: XXXX # how can i retrieve idorder from output of createOrder above ? ????
}
}) {
product {
idproduct
}
}
}
带有SQL结构的实例:
user(iduser, othersFields);
scenarios(idscenario, iduser, name, otherFields);
cultA(idcultA, idscenario, ...); // this table need of idscenario field
cultB(idcultB, idscenario, ...); // this table need of idscenario field
cultC(idcultC, idscenario, ...); // this table need of idscenario field
如何从上面的 createOrder 输出中检索 idorder ? ????
有可能吗?
如果我忘记了一些信息,请不要犹豫。
提前致谢。
编辑:
- 使用 PostGraphile,插件“postgraphile-plugin-nested-mutations”或“自定义突变”(带有 PL PGSQL 函数)
- 如果没有 PostGraphile,解析器(如 @xadm 的示例)允许这种特殊的嵌套突变。
【问题讨论】:
-
可能正在寻找“嵌套突变”
-
我看到了“嵌套突变”,但是我没有找到我的用例。我想真正检索按顺序生成的 id,因为我需要它来运行在同一查询中的产品和其他表中执行插入。您是否已经在“嵌套突变”中使用了变量?
标签: graphql postgraphile