This might be another way to tackle this problem. I'm using Graphql to build a live chat app and I was trying to give the user the power to delete their messages when I came across this solution.
let messages = []
My definitions:
type Query {
messages: [Message!]
}
type Mutation {
deleteMessage(id:String!):String
}
My resolvers:
Query: {
messages: () => messages,
}
Mutation: {
deleteMessage: (parent, {id}) => {
let ID = parseInt(id)
messages = messages.filter((message) => message.id !== ID);
return id;
}
}
I query the messages and put them in the array named messages and then when the user wants
to delete the message from the frontend the action send the id of the message to the server
and then I use the filter method above to remove the specified message.