Instructor: 0:00 Let's take a look at how we can extend a GraphQL mutation. Right here, you can see the last mutation we tested out. What I would do is to treat this mutation like it's going to expect a query variable or query variables. To do that, let's first of all rename this to insert_user so it can be more meaningful.
0:20 Then the first query variable would be username, which is, of course, going to be type string. The next one is password, which is going to be of type string as well. What we're going to do is to remove these hard-coded values and replace them with the variables we are expecting, the password as well.
0:58 If you come down to the query variable section, you can test this out to confirm that it's working. You can have Abdah, and the password can be Abdah's password. If we execute this, you should see that we still have a response. You can test this as well, by going to the user table and see that we have a new field here.
1:28 The next thing we need to do is to intercept this mutation with our serverless function. This is where extending our endpoint comes in. What you need to do is click this Derive action button right here. Now this would create a new action for you.
1:44 You can see that the username and password query variables we passed in earlier are now parameters to this mutation. The mutation is meant to return an insert_user output type, which is the affected rows.
1:58 Now we need to replace this port with what we've created earlier, which is our serverless function. We're just going to copy this and paste it here. This link basically inaudible looks inaudible machine. I can click on Create, and this would create this action. If you scroll up, you can see the code that is generated, that you can use to intercept this request in your serverless function.
2:44 Now, whenever this engine has to execute the insert user mutation, which you have right here, the first thing it's going to do is to make sure to execute the URL you specified when you created the insert_user action which is here.
3:00 Once it hits this URL and this URL sends a successful response, then the insert mutation or the insert_user mutation can go ahead and succeed.