Instructor: 00:00 To create mutation, first we need to create input type. I'm going to create a new input type, product(input). You must define the properties or attributes here. We need title, and the type of the title is string. I also need quantity or QTY. The type of quantity is integer.
00:24 Now we need to create a new mutation type, mutation. The first mutation is createProduct, and it will accept input argument. The input argument is input, and the type of this input is product(input), and it will return the product.
00:48 Now we need to create a resolver for this createProduct. I'm going to open the resolver.js file. Here, I'm going to create my mutation first. I'm going to place all my mutation inside the mutation object. The name of the mutation is createProduct.
01:05 Here, we need to define all the arguments. The first argument is root, and I'm going to use destructuring to destructure the input. I don't need context and info. I'm going to use async/await, so let's convert this function to async/await. Now I can use await expression.
01:27 I have already imported the product.model from the mongoose.model. Here we have product.model. Each product has title and quantity. You can use create method. I'm going to provide the input here, and it will return the promise. I'm going to apply await expression, and promise will be resolved. It will return a new product.
01:50 Incredible, everything looks good so far. Let's try to test it from the GraphQL. I'm going to refresh my browser. Let me check my inaudible . Incredible. Did you see that? Here, we have mutation.
02:02 Let me show you the createProduct mutation. Here we have createProduct mutation. Let's try to execute the createProduct mutation. It will take the product(input), and we need to provide the title and quantity.
02:14 First we need to execute the mutation, have only to provide the name of the mutation and it will accept input argument. We need to provide the title. I'm going to choose GraphQL, of course. QTY is integer. Here, I need to inaudible GraphQL. I want to see the ID in the response. I also want to see the quantity and I also want to see the title.
02:38 Incredible, here we have a new product. Let's try to fetch all the products. I'm going to execute the query for all products. I will like to see ID, title, and QTY. Incredible, there is only one product here.