I have a graphql delete mutation that works perfectly with Strapi in the graphql plugin playground. In a Vuejs frontend I cannot get the mutation to read the id of the item to delete.
The query in the graphql playground is
mutation deleteInvoice ($id: deleteInvoiceInput!) {
deleteInvoice(input: $id) {
invoice {
id
}
}
}
Query variables
{ "id": "618bacab6a2a1b2f7407a8e8" }
The frontend display is a list with button to delete each item
<tr v-for="(item, id) in result.invoices" :key="id" id="delete-item">
<td>{{ item.id }}</td>
<button @click="onDeleteClicked(item)" uk-icon="icon: trash"></button>
</td>
const { mutate: deleteInvoice } = useMutation(gql`
mutation deleteInvoice($id: ID!) {
deleteInvoice(input: { where: { id: $id } }) {
invoice {
id
}
}
}`,
(id) => ({
variables: { id }
})
)
const onDeleteClicked = (item) => {
deleteInvoice({ variables: { item: item.id} })
alert(item.id)
}
the alert displays correctly the id of the item clicked - but the id is not passed the mutation
how to pass the id of the item clicked to the mutation?