[英]GraphQL - Is it possible to set a variable with a result for a mutation
我想在我的 GraphQL 查询中创建 2 个。 (我知道我的查询结构不正确,但这是为了说明我的问题)
mutation {
affiliateCreate(company: "test mutation") {
$id: id,
affiliateUserCreate(affiliate_id: $id, name: "test name") {
id,
name
},
company
}
}
我希望我的第一个 id 结果在我传递给第二个创建调用的变量中? 我对 GraphQL 很陌生,我想知道是否有可能。
有没有其他方法可以做这样的事情? 或者我必须做 2 个突变调用? 第一个与affiliateCreate
并在它的后备第二个?
谢谢
GraphQL 不支持您要执行的操作。 在 Graphcool API 中,我们通过所谓的嵌套突变来处理这种情况。 我也听说它被称为复杂突变。
嵌套的 create 突变的特点是嵌套的输入对象参数。 如果您将输入对象author
添加到affiliateCreate
突变,您可以像这样使用它:
mutation createAffiliateAndUser {
affiliateCreate(
company: "test company"
author: {
name: "test user"
}
) {
id
}
}
这将创建一个会员、一个用户,然后将两者链接在一起。 类似地,如果您向userCreate
突变添加一个输入对象affiliates
,它可能如下所示:
mutation createUserAndAffiliates {
userCreate(
name: "test user"
affiliates: [{
company: "first company"
}, {
company: "second company"
}]
) {
id
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.