我想在我的GraphQL查询中做2次创作.(我知道我的查询结构不正确,但这是为了说明我的问题)
mutation {
affiliateCreate(company: "test mutation") {
$id: id,
affiliateUserCreate(affiliate_id: $id, name: "test name") {
id,
name
},
company
}
}
Run Code Online (Sandbox Code Playgroud)
我希望我的第一个id结果是变量,我传递给第二个创建调用?我是GraphQL的新手,我想知道它是否可行.
有没有其他方法可以做这样的事情?或者我必须做2个变异调用?第一个affiliateCreate和第二个是第二个?
谢谢
GraphQL不支持您想要做的事情.在Graphcool API中,我们使用所谓的嵌套突变来处理这种情况.我也听说它被称为复杂的突变.
嵌套的创建变异以嵌套的输入对象参数为特征.如果您将一个输入对象添加author到affiliateCreate变异中,您可以像这样使用它:
mutation createAffiliateAndUser {
affiliateCreate(
company: "test company"
author: {
name: "test user"
}
) {
id
}
}
Run Code Online (Sandbox Code Playgroud)
这将创建一个联盟会员,一个用户,然后将两者链接在一起.类似地,如果您affiliates向userCreate突变添加输入对象,它可能如下所示:
mutation createUserAndAffiliates {
userCreate(
name: "test user"
affiliates: [{
company: "first company"
}, {
company: "second company"
}]
) {
id
}
}
Run Code Online (Sandbox Code Playgroud)
阅读本文中有关嵌套突变的更多信息.
| 归档时间: |
|
| 查看次数: |
855 次 |
| 最近记录: |