Bird
Raised Fist0
GraphQLquery~20 mins

Input arguments for mutations in GraphQL - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Mutation Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ query_result
intermediate
2:00remaining
Mutation with required input argument
Given the following GraphQL mutation schema, what will be the result of this mutation call?

mutation {
  addUser(name: "Alice") {
    id
    name
  }
}

Schema snippet:
type Mutation {
  addUser(name: String!): User
}
type User {
  id: ID!
  name: String!
}
A{"data": {"addUser": {"id": "1", "name": "Alice"}}}
B{"data": {"addUser": null}}
C{"errors": [{"message": "Field 'addUser' argument 'name' of type 'String!' is required but not provided."}]}
D{"data": {"addUser": {"id": null, "name": "Alice"}}}
Attempts:
2 left
💡 Hint
The mutation requires a non-null string argument 'name'.
📝 Syntax
intermediate
2:00remaining
Identify the syntax error in mutation input
Which option contains a syntax error in the mutation input arguments?
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") { id name } }
Attempts:
2 left
💡 Hint
Check the commas between arguments and string quoting.
❓ optimization
advanced
2:00remaining
Optimizing mutation input for multiple fields
You want to update a user's profile with many fields: name, email, age, and address. Which input argument style is best for scalability and clarity?
Amutation { updateUser(id: 1, input: {name: "Eve", email: "eve@example.com", age: 30, address: "123 St"}) { id name } }
Bmutation { updateUser(id: 1, name: "Eve", email: "eve@example.com", age: 30, address: "123 St") { id name } }
Cmutation { updateUser({id: 1, name: "Eve", email: "eve@example.com", age: 30, address: "123 St"}) { id name } }
Dmutation { updateUser(id: 1, fields: ["name", "email", "age", "address"], values: ["Eve", "eve@example.com", 30, "123 St"]) { id name } }
Attempts:
2 left
💡 Hint
Consider grouping related fields into one input object.
🔧 Debug
advanced
2:00remaining
Why does this mutation fail?
Given this mutation call:
mutation {
  createPost(title: "Hello") {
    id
    title
  }
}

And this schema snippet:
type Mutation {
  createPost(input: PostInput!): Post
}
input PostInput {
  title: String!
  content: String!
}
type Post {
  id: ID!
  title: String!
  content: String!
}

Why does the mutation fail?
AThe mutation does not provide the 'input' argument as required by the schema.
BThe mutation is missing the required 'content' field inside the 'input' argument.
CAll of the above.
DThe mutation uses 'title' as a direct argument instead of inside 'input'.
Attempts:
2 left
💡 Hint
Check how the mutation arguments match the schema.
🧠 Conceptual
expert
2:00remaining
Understanding input argument types in mutations
Which statement about input arguments in GraphQL mutations is TRUE?
AYou cannot use lists as input arguments in mutations.
BInput object types can be used as arguments to group multiple fields into one argument.
CMutation input arguments must always be nullable to allow partial updates.
DScalar types cannot be used as mutation input arguments.
Attempts:
2 left
💡 Hint
Think about how to organize multiple fields in mutation inputs.

Practice

(1/5)
1. What is the main purpose of input arguments in GraphQL mutations?
easy
A. To send data to create, update, or delete records
B. To define the schema of queries
C. To style the GraphQL interface
D. To fetch data without any changes

Solution

  1. Step 1: Understand the role of mutations

    Mutations in GraphQL are used to change data, such as creating or updating records.
  2. Step 2: Identify the use of input arguments

    Input arguments provide the data needed for these changes, like new values or identifiers.
  3. Final Answer:

    To send data to create, update, or delete records -> Option A
  4. Quick Check:

    Input arguments = send data for mutations [OK]
Hint: Input arguments send data to mutations for changes [OK]
Common Mistakes:
  • Confusing input arguments with query filters
  • Thinking input arguments style the API
  • Assuming mutations fetch data only
2. Which of the following is the correct way to define an input argument for a mutation in GraphQL?
easy
A. mutation addUser(name: String!) { createUser(name: name) { id } }
B. mutation addUser($name: String!) { createUser(name: $name) { id } }
C. mutation addUser { createUser(name: String!) { id } }
D. mutation addUser($name) { createUser(name: $name) { id } }

Solution

  1. Step 1: Recognize variable declaration syntax

    Input arguments must be declared with a $ prefix and type, like $name: String!.
  2. Step 2: Use variables inside mutation

    Inside the mutation body, use the variable with $name to pass the value.
  3. Final Answer:

    mutation addUser($name: String!) { createUser(name: $name) { id } } -> Option B
  4. Quick Check:

    Variables use $name: Type! and $name inside mutation [OK]
Hint: Declare variables with $ and type, use $ inside mutation [OK]
Common Mistakes:
  • Omitting $ in variable declaration
  • Using type inside mutation call instead of variable
  • Not specifying variable type
3. Given the mutation and variables below, what will be the returned id after execution?

mutation updateUser($id: ID!, $email: String!) { updateUser(id: $id, email: $email) { id email } }
{ "id": "123", "email": "new@example.com" }
medium
A. "123"
B. "new@example.com"
C. null
D. Error: Missing required fields

Solution

  1. Step 1: Understand mutation input and output

    The mutation updates the user with id "123" and new email, returning the user's id and email.
  2. Step 2: Identify returned id value

    The returned id is the same as the input id, which is "123".
  3. Final Answer:

    "123" -> Option A
  4. Quick Check:

    Returned id matches input id "123" [OK]
Hint: Returned id matches input id argument [OK]
Common Mistakes:
  • Confusing returned id with email
  • Assuming null if email changes
  • Expecting error without missing fields
4. Identify the error in this mutation definition:

mutation deleteUser(id: ID!) { removeUser(id: id) { success } }
medium
A. removeUser field cannot have arguments
B. Variable type ID! is incorrect
C. Mutation name deleteUser is invalid
D. Missing $ before variable name in mutation definition

Solution

  1. Step 1: Check variable declaration syntax

    Variables in mutation definitions must start with $, e.g., $id: ID!.
  2. Step 2: Verify usage inside mutation

    Inside the mutation body, use the variable with $id, not just id.
  3. Final Answer:

    Missing $ before variable name in mutation definition -> Option D
  4. Quick Check:

    Variables require $ prefix in definition and usage [OK]
Hint: Always prefix variables with $ in mutation definitions [OK]
Common Mistakes:
  • Omitting $ in variable declaration
  • Using variable name without $ inside mutation
  • Assuming mutation name must match field
5. You want to create a mutation that accepts a complex input object with fields title (String), content (String), and tags (list of Strings). Which is the correct way to define the input argument and use it in the mutation?
hard
A. type PostInput { title: String!, content: String!, tags: [String!]! }
mutation createPost(post: PostInput!) { addPost(post: post) { id } }
B. input PostInput { title: String, content: String, tags: String }
mutation createPost($post: PostInput) { addPost(post: $post) { id } }
C. input PostInput { title: String!, content: String!, tags: [String!]! }
mutation createPost($post: PostInput!) { addPost(input: $post) { id } }
D. input PostInput { title: String!, content: String!, tags: [String] }
mutation createPost($post: PostInput!) { addPost(input: post) { id } }

Solution

  1. Step 1: Define input type correctly

    Use input keyword with required fields and list type: tags: [String!]! means list of non-null strings, list itself required.
  2. Step 2: Declare variable and use it properly

    Declare variable with $post: PostInput! and use it as input: $post inside mutation.
  3. Final Answer:

    input PostInput { title: String!, content: String!, tags: [String!]! }
    mutation createPost($post: PostInput!) { addPost(input: $post) { id } }
    -> Option C
  4. Quick Check:

    Use input type and $variable with correct usage [OK]
Hint: Use input type and $variable with correct usage inside mutation [OK]
Common Mistakes:
  • Using type instead of input for input objects
  • Omitting $ in variable declaration or usage
  • Incorrect list type syntax or missing non-null markers
  • Passing variable without $ inside mutation
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