简体   繁体   中英

How to map a list in a graphql mutation query

What the list object looks like

What the Retool table looks like

I am creating a Retool dashboard and allowing a user to edit rows of an organization table and once the user makes changes I would like to update the database with a Graphql mutation query.

I am trying to map this array (2 rows were edited in this case) in a mutation query to update my database for these two organizations only.

So far I have tried something like this but I keep on getting an error that this is not a valid Graphql query.

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`)
    )
    }}
}

The update_orgs_by_pk query is fine as it works on hasura when I tried using info to mutate one organization, but I can't seem to figure out how to map a list and do multiple mutations.

Actually, what you are looking for is Retool - MongoDB bulkWrite query, I am using this approach to update edited records from table component.

My handler, (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;

Resource query ,

来自 retool 的资源查询

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM