[英]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.