0
0
GraphQLquery~20 mins

Mutation syntax in GraphQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
GraphQL Mutation Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
What is the result of this mutation?
Given this GraphQL mutation to add a new user:
mutation {
addUser(name: "Alice", age: 30) {
id
name
age
}
}

Assuming the server assigns id 101 to the new user, what is the expected output?
GraphQL
mutation {
  addUser(name: "Alice", age: 30) {
    id
    name
    age
  }
}
A{ "data": { "addUser": { "id": 101, "name": "Alice", "age": 30 } } }
B{ "data": { "addUser": { "name": "Alice", "age": 30 } } }
C{ "data": { "addUser": { "id": "101", "name": "Alice", "age": "30" } } }
D{ "error": "Field 'id' not found" }
Attempts:
2 left
💡 Hint
Remember the server returns all requested fields with their correct types.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this mutation
Which option contains a syntax error in this GraphQL mutation?
mutation {
updateUser(id: 5, name: "Bob") {
id
name
}
}
GraphQL
mutation {
  updateUser(id: 5, name: "Bob") {
    id
    name
  }
}
Amutation { updateUser(id: 5, name: "Bob") { id name }
Bmutation { updateUser(id: 5 name: "Bob") { id name } }
Cmutation { updateUser(id: 5, name: "Bob") { id name } }
Dmutation updateUser { id: 5, name: "Bob" }
Attempts:
2 left
💡 Hint
Check commas between arguments and braces.
optimization
advanced
2:00remaining
Optimize this mutation to reduce response size
You want to update a user's email but only need the updated email in the response. Which mutation is optimized for minimal response size?
Amutation { updateUser(id: 10, email: "new@example.com") { id name email age } }
Bmutation { updateUser(id: 10, email: "new@example.com") { name email } }
Cmutation { updateUser(id: 10, email: "new@example.com") { id email } }
Dmutation { updateUser(id: 10, email: "new@example.com") { email } }
Attempts:
2 left
💡 Hint
Request only the fields you need to reduce data transfer.
🔧 Debug
advanced
2:00remaining
Why does this mutation cause an error?
Consider this mutation:
mutation {
deleteUser(id: "abc") {
id
}
}

It causes an error. What is the most likely reason?
GraphQL
mutation {
  deleteUser(id: "abc") {
    id
  }
}
AThe mutation is missing a closing brace.
BThe deleteUser field requires a name argument.
CThe id argument should be an integer, not a string.
DThe id argument is missing.
Attempts:
2 left
💡 Hint
Check the expected type of the id argument.
🧠 Conceptual
expert
3:00remaining
What happens if a mutation requests a non-existent field?
Given this mutation:
mutation {
addUser(name: "Eve", age: 25) {
id
nickname
}
}

Assuming 'nickname' is not a valid field on User, what will the server respond?
GraphQL
mutation {
  addUser(name: "Eve", age: 25) {
    id
    nickname
  }
}
A{ "errors": [{ "message": "Cannot query field 'nickname' on type 'User'." }] }
B{ "error": "Field 'nickname' is deprecated" }
C{ "data": { "addUser": { "id": 102 } } }
D{ "data": { "addUser": { "id": 102, "nickname": null } } }
Attempts:
2 left
💡 Hint
GraphQL validates requested fields against the schema before execution.