Challenge - 5 Problems
useMutation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate2:00remaining
What is the result of this mutation call?
Given the following GraphQL mutation using
useMutation, what will be the value of data after the mutation completes successfully?GraphQL
const [addUser, { data, loading, error }] = useMutation(ADD_USER); addUser({ variables: { name: "Alice", age: 30 } });
Attempts:
2 left
💡 Hint
The
data object contains the server response after the mutation completes.✗ Incorrect
When the mutation completes successfully,
data holds the returned object from the server, which includes the new user's details.🧠 Conceptual
intermediate1:30remaining
What does the
useMutation hook return?Which of the following correctly describes the values returned by the
useMutation hook in Apollo Client?Attempts:
2 left
💡 Hint
Think about how React hooks usually return multiple values.
✗ Incorrect
The
useMutation hook returns a tuple: the first element is the mutation function, and the second is an object with the mutation's current state.📝 Syntax
advanced2:00remaining
Identify the syntax error in this mutation usage
Which option contains the correct syntax to call a mutation with variables using
useMutation?GraphQL
const [updateUser] = useMutation(UPDATE_USER);
updateUser(???);Attempts:
2 left
💡 Hint
The variables must be passed inside an object with a key named
variables.✗ Incorrect
The mutation function expects an object with a
variables property containing the variables object.❓ optimization
advanced2:30remaining
How to update the cache after a mutation?
After running a mutation with
useMutation, which option correctly updates the Apollo Client cache to include the new item?Attempts:
2 left
💡 Hint
Manual cache updates allow precise control without extra network requests.
✗ Incorrect
The
update function lets you write directly to the Apollo cache after a mutation, avoiding unnecessary refetches.🔧 Debug
expert3:00remaining
Why does this mutation cause an error?
Consider this mutation call:
const [deleteUser] = useMutation(DELETE_USER);
deleteUser({ variables: { id: undefined } });
What error will this cause and why?Attempts:
2 left
💡 Hint
Required variables must be provided with valid values.
✗ Incorrect
The mutation expects a non-null ID, but
undefined was passed, causing a GraphQL validation error.