Skip to content

Mutation Templates with prop value - Vue3 #1189

Answered by rabrowne85
rabrowne85 asked this question in Q&A
Discussion options

You must be logged in to vote

So, as is generally the case, I write a post and then answer it myself 🤦

I wasn't actually that far away. These are the necessary changes:

  1. Change the definition of the deleteMutationTemplate to the following:
export const deleteMutationTemplate = (typeName) => gql `
mutation delete ($id: ID!) {
    delete${typeName} (id: $id) {
        id
    }
}
`;

This now expects a single parameter to be passed, rather than an object as before.

  1. The mutation no longer needs to be computed and can be "simplified" as follows:
const { mutate: deleteItem } = useMutation(
    deleteMutationTemplate(props.type),
    {
        variables: {
            id: props.item.id
        }
    }
);

This then allows y…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by rabrowne85
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant