Complete the code to import the useMutation hook from Apollo Client.
import { [1] } from '@apollo/client';
The useMutation hook is imported from '@apollo/client' to perform GraphQL mutations.
Complete the code to define a mutation using gql tagged template literal.
const ADD_TODO = gql`mutation AddTodo($text: String!) { addTodo(text: [1]) { id text } }`;In GraphQL mutations, variables are referenced with a $ prefix, so $text is correct.
Fix the error in the mutation call to pass variables correctly.
const [addTodo] = useMutation(ADD_TODO);
addTodo({ variables: [1] });The variables option expects an object with keys matching the mutation variables, so { text } is correct.
Fill both blanks to destructure the mutation result and call the mutation function.
const [[1], { [2] }] = useMutation(ADD_TODO);
The first element is the mutation function addTodo, and the second is an object containing data about the mutation result.
Fill all three blanks to handle mutation with async/await and error catching.
try { const [1] = await addTodo({ variables: { text: newText } }); console.log([2]); } catch ([3]) { console.error('Error:', error); }
The mutation result is stored in result. To access the data, use result.data. Errors are caught in the catch block as error.