Hello i am making recipe app and at this point i have to create editing functionality by getting update mutation from hasura.But i have issues trying to create this mutation.Because there are two tables related to each other, one of them is recipes and other related by id is ingredient which is a array of objects .I need to populate existing form with a dynamic ingredient field with existing recipe data and then to be able to edit that data .At first i thought i will be able to create something similar to what i did with insert mutation but inserting and updating have diferent properties and im abit lost here.
here is how i wrote my insertion mutation which is working fine
mutation insertRecipe(
$title: String!
$image: String!
$description: String!
$Date: date!
$ingredient_relation: [ingredient_insert_input!]!
) {
insert_recipes(
objects: {
title: $title
image: $image
description: $description
Date: $Date
ingredient_relation: { data: $ingredient_relation }
}
) {
returning {
id
}
}
}
and here is my atempt at updating mutation but update doesent have data property which i used in insert mutation
mutation recipe_edit(
$title: String!
$id: Int!
$image: String!
$description: String!
$Date: date!
$ingredient_relation: [ingredient_insert_input!]!
) {
update_recipes(
_set: {
title: $title
image: $image
description: $description
Date: $Date
}
where: { id: { _eq: $id } }
) {
returning {
id
}
}
update_ingredient(
_set: { data: $ingredient_relation }
where: { recipe_id: { _eq: $id } }
) {
returning {
id
}
}
}
I also made fully working updating withouth variables it works only in hasura graphiql interface
mutation UpdateRecipe {
update_recipes(_set: {title: "lets change title", image: "https://upload.wikimedia.org/wikipedia/commons/thumb/5/5e/Vytautas_the_Great_Bridge_from_hill%2C_Kaunas%2C_Lithuania_-_Diliff.jpg/1280px-Vytautas_the_Great_Bridge_from_hill%2C_Kaunas%2C_Lithuania_-_Diliff.jpgs", description: "new description", Date: "1991-06-09"}, where: {id: {_eq: 10}}) {
affected_rows
}
update_ingredient(_set: {name: "lets change the name"}, where: {recipe_id: {_eq: 10}}) {
affected_rows
}
}