⚠️ This lesson is retired and might contain outdated information.

Extend a Mutation with a Azure serverless function with GraphQL Actions

Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 2 years ago

In this lesson, we'll extend our User table mutation to accept username and password arguments. Then we'll intercept this mutation with the serverless function that we have set up.

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:27] You can just copy this JavaScript file, execute it or treat it like it's a Node file, and then make sure it's exposed to a port that you've specified when you were creating the insert_user action.

[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.

egghead
egghead

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today