A mutation is a special type of GraphQL operation used to create, update, or delete data on the server.
Click to reveal answer
beginner
What is the basic structure of a create mutation in GraphQL?
A create mutation usually has a name, input arguments for the new data, and specifies the fields to return after creation.
Click to reveal answer
beginner
Why do we specify return fields in a GraphQL mutation?
Because GraphQL lets clients ask for exactly what they need, specifying return fields ensures the client gets the necessary data after the mutation runs.
Click to reveal answer
intermediate
Example: Write a simple create mutation to add a new user with name and email.
mutation {
createUser(name: "Alice", email: "alice@example.com") {
id
name
email
}
}
Click to reveal answer
intermediate
What is the role of input types in create mutations?
Input types group related fields into one argument, making mutations cleaner and easier to manage, especially for many fields.
Click to reveal answer
What keyword starts a mutation operation in GraphQL?
Amutation
Bquery
Cupdate
Dcreate
✗ Incorrect
The keyword 'mutation' is used to start a mutation operation in GraphQL.
In a create mutation, what do you usually provide as input?
AThe database name
BThe fields to delete
CThe fields of the new data to create
DThe server IP address
✗ Incorrect
You provide the fields of the new data you want to create as input.
Why do you specify fields after the mutation call?
ATo ignore those fields
BTo delete those fields
CTo update those fields
DTo tell the server what data to return after mutation
✗ Incorrect
Specifying fields tells the server what data to send back after the mutation.
Which of these is a valid mutation name for creating a user?
AlistUsers
BcreateUser
CdeleteUser
DgetUser
✗ Incorrect
'createUser' is a typical name for a mutation that creates a user.
What is the benefit of using input types in mutations?
AThey group input fields for cleaner code
BThey speed up the server
CThey encrypt data
DThey delete old data
✗ Incorrect
Input types group related input fields, making the mutation easier to read and manage.
Explain the steps to write a create mutation in GraphQL.
Think about how you tell the server what to create and what to get back.
You got /4 concepts.
Describe why specifying return fields in a mutation is important.
Consider how GraphQL differs from traditional APIs in data fetching.
You got /4 concepts.
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
Step 1: Understand GraphQL operation types
GraphQL has queries for reading data and mutations for changing data.
Step 2: Identify mutation role
Mutations are used to create, update, or delete data in the database.
Final Answer:
To create, update, or delete data in the database -> Option B
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
Step 1: Recall mutation syntax with variables
Variables in GraphQL mutations start with $ and have a colon before the type.
Step 2: Check each option
mutation createUser($input: CreateUserInput!) { ... } correctly uses $input: CreateUserInput!. Others miss $ or colon.
Final Answer:
mutation createUser($input: CreateUserInput!) { ... } -> Option A
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
Step 1: Identify requested return fields
The mutation requests id and title fields inside addBook.
Step 2: Understand GraphQL response
GraphQL returns only the fields explicitly requested, so only id and title are returned.
Final Answer:
Only the id and title of the new book -> Option D
Quick Check:
Requested fields = returned fields [OK]
Hint: Returned fields match exactly requested fields in mutation body [OK]
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
Step 1: Check argument name in mutation call
The mutation calls createPost(post: $post), but server expects input argument.
Step 2: Correct argument name
Changing post to input matches server expectation and fixes error.
Final Answer:
The argument name post should be input -> Option C
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
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.
Step 2: Verify requested return fields
mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } requests id and email, matching the question requirement.
Final Answer:
mutation AddUser($input: UserInput!) { addUser(input: $input) { id email } } -> Option A
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 unknownstrongwhile earning +1 Grip toward your certificate.