0

how we can set seperate update_columns list for each object inside the array object while using on_conflct upsert?

eg: i have a table called User and it have fields like id,name and age

Requirement: in the upsert action i need to upsert a list of user.. like user1(need to update age field only), user2(need to update name), user3(need to update age and name). currently update_columns is common. so how we can set update_columns to object level?

Sarath Baiju
  • 226
  • 2
  • 9

1 Answers1

1

You can pass the update_columns as a variable to your mutation. If you check the docs in the GraphiQL tab, under mutation_root you can see the types that Hasura autogenerates. I believe the type for the update_columns for the table user will be something like user_update_column

You mutation, having the update_columns as a variable will look something like this:

mutation ($update_columns:  [user_update_column!]!) {
  insert_users(
    objects: {id: "1", name: "name", email: "joe@gmail.com", age: 30},
    on_conflict: { 
      constraint: users_pkey, 
      update_columns: $update_columns
    }
  ){
    id
    name
    email
  }
}

And pass the columns that you need to update as the variable.

Leonardo Alves
  • 1,876
  • 1
  • 16
  • 19
  • update_columns property just for setting what are the columns need to update during the mutation call. here if i set update_columns = [name], then after the mutation call only the name field of that particular record will update – Sarath Baiju Aug 09 '21 at 11:45