0
0
GraphQLquery~20 mins

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

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