簡體   English   中英

如何在 graphql 突變查詢中映射列表

[英]How to map a list in a graphql mutation query

列表對象的樣子

Retool 表的外觀

我正在創建一個 Retool 儀表板並允許用戶編輯組織表的行,一旦用戶進行更改,我想使用 Graphql 突變查詢更新數據庫。

我試圖在突變查詢中映射這個數組(在這種情況下編輯了 2 行),以便僅為這兩個組織更新我的數據庫。

到目前為止,我已經嘗試過這樣的事情,但我不斷收到一個錯誤,即這不是有效的 Graphql 查詢。

mutation edit_org_details { 
  {{
    orgs_table.recordUpdates.map(updates => (`\n
        update_orgs_by_pk(\n
      _set: {\n
        name: "${updates.name}",\n
        legal_entity_name: "${updates.legal_entity_name}",\n
        industry: "${updates.industry}",\n
        country: "${updates.country}",\n
        status: "${updates.status}" \n
      },\n
      pk_columns: {\n
        id: "${updates.id}"\n
        } { \n
        name \n
      })\n`)
    )
    }}
}

update_orgs_by_pk 查詢很好,因為當我嘗試使用 info 來改變一個組織時,它可以在 hasura 上運行,但我似乎無法弄清楚如何映射一個列表並進行多個突變。

實際上,您正在尋找的是 Retool - MongoDB bulkWrite 查詢,我正在使用這種方法來更新表組件中的已編輯記錄。

我的處理程序,(bulkUpdateHandler)

if (myTable?.recordUpdates.length == 0) return;

let records = myTable?.recordUpdates?.map((r) => ({
    updateOne: {
        "filter": {
            "_id": {
                $oid: r._id
            }
        },
        "update": {
            $set: {
                "name": r.name,
                "year": r.year,
                "month": r.month,
                "day": r.day
            }
        }
    }
}));

return records;

資源查詢

來自 retool 的資源查詢

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM