Introduction
A create mutation lets you add new data to your database. It helps you save new information easily.
A create mutation lets you add new data to your database. It helps you save new information easily.
mutation CreateItem($input: ItemInput!) {
createItem(input: $input) {
id
name
description
}
}The mutation keyword starts the operation to change data.
$input is a variable holding the new data you want to add.
mutation CreateUser($input: UserInput!) {
createUser(input: $input) {
id
username
email
}
}mutation AddProduct($input: ProductInput!) {
addProduct(input: $input) {
id
title
price
}
}This mutation adds a new book with its title and author.
mutation CreateBook($input: BookInput!) {
createBook(input: $input) {
id
title
author
}
}
# Variables:
# {
# "input": {
# "title": "The Great Gatsby",
# "author": "F. Scott Fitzgerald"
# }
# }Always define the input type to specify what data is needed.
Use variables to keep your mutation flexible and reusable.
The server returns the new item's fields you ask for after creation.
Create mutations add new data to your database.
Use mutation keyword with input variables.
Request the fields you want back after creating the item.
mutation in GraphQL?input of type CreateUserInput!?$input: CreateUserInput!. Others miss $ or colon.mutation AddBook($book: BookInput!) {
addBook(input: $book) {
id
title
}
}id and title fields inside addBook.id and title are returned.mutation CreatePost($post: PostInput!) {
createPost(post: $post) {
id
content
}
}input, not post.createPost(post: $post), but server expects input argument.post to input matches server expectation and fixes error.name and email. Which mutation correctly uses input variables and requests the new user's id and email in the response?$input: UserInput! and uses it as input: $input.id and email, matching the question requirement.Pass the test and this pattern moves unknown