Bird
Raised Fist0
GraphQLquery~20 mins

Create mutation pattern 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 GraphQL mutation?

Given the following GraphQL mutation to create a new user, what will be the output if the mutation is successful?

GraphQL
mutation {
  createUser(input: {name: "Alice", email: "alice@example.com"}) {
    id
    name
    email
  }
}
A{ "data": { "createUser": { "name": "Alice" } } }
B{ "data": { "createUser": { "id": "1", "name": "Alice", "email": "alice@example.com" } } }
C{ "errors": [ { "message": "Field 'createUser' not found" } ] }
D{ "data": { "createUser": null } }
Attempts:
2 left
💡 Hint

Successful mutations return the created object with requested fields.

📝 Syntax
intermediate
2:00remaining
Identify the syntax error in this mutation

Which option correctly fixes the syntax error in this GraphQL mutation?

GraphQL
mutation {
  createUser(input: {name: "Bob", email: "bob@example.com") {
    id
    name
  }
}
A
mutation {
  createUser(input: {name: "Bob", email: "bob@example.com"} {
    id
    name
  }
}
B
mutation {
  createUser(input: {name: "Bob", email: bob@example.com}) {
    id
    name
  }
}
C
mutation {
  createUser(input: {name: "Bob", email: "bob@example.com"}) {
    id
    name
  }
}
D
mutation {
  createUser(input: name: "Bob", email: "bob@example.com") {
    id
    name
  }
}
Attempts:
2 left
💡 Hint

Check for balanced parentheses and correct object syntax.

❓ optimization
advanced
2:00remaining
Optimize this mutation to reduce response size

You want to create a new post but only need the post ID in the response. Which mutation query is optimized for this?

GraphQL
mutation {
  createPost(input: {title: "Hello", content: "World"}) {
    id
    title
    content
    createdAt
  }
}
A
mutation {
  createPost(input: {title: "Hello", content: "World"}) {
    id
  }
}
B
mutation {
  createPost(input: {title: "Hello", content: "World"}) {
    title
  }
}
C
mutation {
  createPost(input: {title: "Hello", content: "World"}) {
    id
    title
  }
}
D
mutation {
  createPost(input: {title: "Hello", content: "World"}) {
    id
    content
  }
}
Attempts:
2 left
💡 Hint

Request only the fields you need to reduce response size.

🔧 Debug
advanced
2:00remaining
Why does this mutation return an error?

Given this mutation, why does it return an error?

GraphQL
mutation {
  createUser(input: {name: "Eve"}) {
    id
    name
    email
  }
}
AThe mutation is missing a closing brace causing a syntax error.
BThe mutation name createUser is invalid and does not exist in the schema.
CThe requested fields id, name, and email are not selectable in the response.
DThe email field is required in input but missing, causing a validation error.
Attempts:
2 left
💡 Hint

Check required input fields in the schema.

🧠 Conceptual
expert
2:00remaining
What is the purpose of the input type in GraphQL mutations?

Why do GraphQL mutations commonly use an input type object for arguments instead of separate scalar arguments?

ATo group related fields into a single argument for better structure and future extensibility.
BTo force clients to send all fields even if they are optional.
CTo make the mutation syntax identical to queries.
DTo prevent mutations from returning any data in the response.
Attempts:
2 left
💡 Hint

Think about how input objects help organize data.

Practice

(1/5)
1. What is the main purpose of a mutation in GraphQL?
easy
A. To optimize query performance
B. To create, update, or delete data in the database
C. To define the schema types
D. To fetch data without changing it

Solution

  1. Step 1: Understand GraphQL operation types

    GraphQL has queries for reading data and mutations for changing data.
  2. Step 2: Identify mutation role

    Mutations are used to create, update, or delete data in the database.
  3. Final Answer:

    To create, update, or delete data in the database -> Option B
  4. Quick Check:

    Mutation = change data [OK]
Hint: Mutations always change data, queries only read data [OK]
Common Mistakes:
  • Confusing mutations with queries
  • Thinking mutations only fetch data
  • Mixing schema definition with data operations
2. Which of the following is the correct syntax to start a mutation with an input variable named input of type CreateUserInput!?
easy
A. mutation createUser($input: CreateUserInput!) { ... }
B. query createUser(input: CreateUserInput!) { ... }
C. mutation createUser(input CreateUserInput!) { ... }
D. mutation createUser($input CreateUserInput!) { ... }

Solution

  1. Step 1: Recall mutation syntax with variables

    Variables in GraphQL mutations start with $ and have a colon before the type.
  2. Step 2: Check each option

    mutation createUser($input: CreateUserInput!) { ... } correctly uses $input: CreateUserInput!. Others miss $ or colon.
  3. Final Answer:

    mutation createUser($input: CreateUserInput!) { ... } -> Option A
  4. Quick Check:

    Variables need $ and colon [OK]
Hint: Variables start with $ and use colon before type [OK]
Common Mistakes:
  • Omitting $ before variable name
  • Missing colon between variable and type
  • Using query instead of mutation keyword
3. Given this mutation:
mutation AddBook($book: BookInput!) {
  addBook(input: $book) {
    id
    title
  }
}

What fields will the server return after running this mutation?
medium
A. Only the input object sent
B. All fields of the book including author and publishedYear
C. No fields, mutation returns nothing
D. Only the id and title of the new book

Solution

  1. Step 1: Identify requested return fields

    The mutation requests id and title fields inside addBook.
  2. Step 2: Understand GraphQL response

    GraphQL returns only the fields explicitly requested, so only id and title are returned.
  3. Final Answer:

    Only the id and title of the new book -> Option D
  4. Quick Check:

    Requested fields = returned fields [OK]
Hint: Returned fields match exactly requested fields in mutation body [OK]
Common Mistakes:
  • Assuming all fields return by default
  • Expecting input object to be returned
  • Thinking mutation returns no data
4. Identify the error in this mutation:
mutation CreatePost($post: PostInput!) {
  createPost(post: $post) {
    id
    content
  }
}

Assuming the server expects the input argument to be named input, not post.
medium
A. The mutation keyword should be query
B. The variable $post should be $input
C. The argument name post should be input
D. The return fields id and content are invalid

Solution

  1. Step 1: Check argument name in mutation call

    The mutation calls createPost(post: $post), but server expects input argument.
  2. Step 2: Correct argument name

    Changing post to input matches server expectation and fixes error.
  3. Final Answer:

    The argument name post should be input -> Option C
  4. Quick Check:

    Argument names must match server schema [OK]
Hint: Match argument names exactly as server expects [OK]
Common Mistakes:
  • Using wrong argument name in mutation call
  • Confusing variable name with argument name
  • Changing mutation keyword incorrectly
5. You want to create a mutation to add a new user with fields name and email. Which mutation correctly uses input variables and requests the new user's id and email in the response?
hard
A. mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } }
B. mutation AddUser(input: UserInput!) { addUser(input: input) { id email } }
C. mutation AddUser($user: UserInput!) { addUser(user: $user) { name email } }
D. mutation AddUser($input: UserInput!) { addUser(input: $input) { name } }

Solution

  1. Step 1: Check variable declaration and usage

    mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } correctly declares $input: UserInput! and uses it as input: $input.
  2. Step 2: Verify requested return fields

    mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } requests id and email, matching the question requirement.
  3. Final Answer:

    mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } -> Option A
  4. Quick Check:

    Correct variable and requested fields = mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } [OK]
Hint: Use $variable and request needed fields explicitly [OK]
Common Mistakes:
  • Omitting $ in variable declaration or usage
  • Requesting wrong fields in response
  • Using wrong argument names
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