![](/img/trans.png)
[英]Symfony ApiPlatform GraphQl mutation fails when array of IRI is sent
[英]GraphQL Syntax for mapping array on mutation field
我正在尋找有關語法的建議。 在我的查詢中,我需要我的后端(Graphlite、Symfony)來獲取子項。 我得到常規項目的方式如下,並且工作正常。 我對 GraphQL / Apollo / VueJS / GraphQLite 不夠精通,無法知道哪種技術擁有“{id: $itemId}”語法,我也不知道它叫什么,所以我找不到任何有關它的信息.
insertItem: gql` mutation insertItem(
$itemId: Uuid!,
$childItemIds: [Uuid!]!
) {
insertItem(
item: {id: $itemId},
childItems: { id: { in : { $childItemIds} }
){
// ... stuff
}
}`
因此,鑒於 {id: $itemId} 正確地用於獲取項目,我假設有一些 graphQL 語法可以應用 childItemIds 來獲取 childItems。 這種映射有名稱嗎? 語法是什么?
根據與@UjinT34 的討論,由於這不能與 GraphQL 內聯完成,我在調用突變之前創建了一個 ItemInput 數組:
for (var i = 0, len = item.childItems.length; i < len; i++) {
childItems.push({ id : item.childItems[i].id } )
}
原來的查詢變成了:
insertItem:`` gql` mutation insertItem(
$itemId: Uuid!,
$childItemIds: [ItemInput!]!
) {
insertItem(
item: {id: $itemId},
childItems: $childItemIds
){
// ... stuff
}
}
一旦我明白{id: $item}
不是神奇的 GQL/GraphQLite 語法,而只是一個內聯 javascript object 正在創建,解決方案就變得相當簡單。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.