Bird
Raised Fist0
GraphQLquery~20 mins

Mutation syntax in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 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.

Practice

(1/5)
1. What is the main purpose of a mutation in GraphQL?
easy
A. To define the data schema
B. To fetch data without changing anything
C. To create a new GraphQL server
D. To change data on the server like adding, updating, or deleting records

Solution

  1. Step 1: Understand GraphQL operations

    GraphQL has queries to fetch data and mutations to change data.
  2. Step 2: Identify mutation role

    Mutations are used to add, update, or delete data on the server.
  3. Final Answer:

    To change data on the server like adding, updating, or deleting records -> Option D
  4. Quick Check:

    Mutation = change data [OK]
Hint: Mutations always modify data, queries only read data [OK]
Common Mistakes:
  • Confusing mutations with queries
  • Thinking mutations define schema
  • Assuming mutations create servers
2. Which of the following is the correct basic syntax to start a mutation in GraphQL?
easy
A. mutation { addUser(name: "Alice") { id name } }
B. query { addUser(name: "Alice") { id name } }
C. mutation addUser { name: "Alice" }
D. addUser mutation { name: "Alice" }

Solution

  1. Step 1: Recognize mutation keyword usage

    Mutations start with the keyword mutation followed by braces containing the mutation call.
  2. Step 2: Check correct structure

    mutation { addUser(name: "Alice") { id name } } correctly uses mutation { addUser(...) { ... } } syntax.
  3. Final Answer:

    mutation { addUser(name: "Alice") { id name } } -> Option A
  4. Quick Check:

    Mutation starts with 'mutation' keyword and braces [OK]
Hint: Mutation always starts with 'mutation' keyword and braces [OK]
Common Mistakes:
  • Using 'query' instead of 'mutation'
  • Placing mutation name before 'mutation' keyword
  • Missing braces around mutation call
3. Given the mutation below, what will be returned?
mutation {
  createPost(title: "Hello") {
    id
    title
  }
}
medium
A. No return data because no fields requested
B. { "data": { "createPost": null } }
C. { "data": { "createPost": { "id": 1, "title": "Hello" } } }
D. Syntax error: missing fields

Solution

  1. Step 1: Analyze mutation call and requested fields

    The mutation calls createPost with title "Hello" and requests id and title fields back.
  2. Step 2: Understand expected return

    The server returns the new post's id and title as requested.
  3. Final Answer:

    { "data": { "createPost": { "id": 1, "title": "Hello" } } } -> Option C
  4. Quick Check:

    Requested fields returned in data [OK]
Hint: Requested fields inside mutation braces are returned [OK]
Common Mistakes:
  • Expecting no return data
  • Confusing syntax error with correct syntax
  • Ignoring requested fields in response
4. Identify the error in this mutation:
mutation {
  updateUser(id: 5, name: "Bob")
}
medium
A. Missing requested return fields after mutation call
B. Wrong keyword, should be 'query' instead of 'mutation'
C. Mutation name 'updateUser' is invalid
D. Extra parentheses around arguments

Solution

  1. Step 1: Check mutation syntax

    Mutation calls must specify which fields to return inside braces after the call.
  2. Step 2: Identify missing return fields

    This mutation lacks braces with requested fields after updateUser, causing syntax error.
  3. Final Answer:

    Missing requested return fields after mutation call -> Option A
  4. Quick Check:

    Mutations must request return fields [OK]
Hint: Always request fields after mutation call in braces [OK]
Common Mistakes:
  • Omitting return fields
  • Using 'query' keyword for mutations
  • Misplacing parentheses
5. You want to delete a user by ID and get back the deleted user's name and email. Which mutation is correct?
hard
A. mutation deleteUser(id: 10) { name email }
B. mutation { deleteUser(id: 10) { name email } }
C. mutation { deleteUser(id: 10) }
D. deleteUser mutation { id: 10, name, email }

Solution

  1. Step 1: Confirm mutation keyword and structure

    Mutation must start with mutation keyword followed by braces containing the mutation call.
  2. Step 2: Check mutation call and requested fields

    mutation { deleteUser(id: 10) { name email } } correctly calls deleteUser with id: 10 and requests name and email fields.
  3. Final Answer:

    mutation { deleteUser(id: 10) { name email } } -> Option B
  4. Quick Check:

    Correct mutation syntax with requested return fields [OK]
Hint: Mutation call inside braces with requested fields in nested braces [OK]
Common Mistakes:
  • Placing mutation name after keyword incorrectly
  • Not requesting return fields
  • Using wrong keyword order
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard