* This is an automated transcript. Please excuse inaccuracies.
Hey everyone, in this video we're going to be going over the basics of using GraphQL, Mutations and 8base specifically that's performing create update and delete actions on your table records, Let's jump right into it.
So, before we start writing our own Mutations, I just wanted to share with you that at docs.8base.com you can go look at Mutations documentation, that will give you some more context around what we're going to be discussing in this video. However, let's jump over to our 8base workspace and in here I create a simple table called “leads” which only stores a name email and phone number. For the sake of the examples we're going to be going with this will work just fine. So, now let's jump to our API Explorer and start writing some Mutations.
So, to get started, I'm first going to remove all these comments, open up the API Explorer a little bit more and write our first create Mutation, so we're going to create our first lead. So, writing a Mutation, giving it brackets and then since we created our lead table, we can see that 8base created a few Mutations for us. So, our operations so we can create a lead we can update a lead we can delete a lead and we can create many leaves at one time. For right now, we're just going to do one lead create pass it a data argument which is going to be an object and then here if we press option space, we can see the different fields that we have specified which are name, email and a phone number. So, first let's throw a name and let's just name this “just lead Jessica”. For an email we're going to say, “ email@example.com. Then finally for a phone number what we're going to do is since we use the smart field for phone number it takes an object which takes the country code there's one argument or parameter and we're going to say plus one and then the actual number for the next one; which we're just going to do it 1, 2, 3, 4, 5, 6, 7, 8, 9- 0. And then we'll specify that okay well if this gets created, all we want back is the ID name. Let's run this Mutation and boom, we can see that okay Jessica was created and that is now her ID.
Jessica is now our first lead and now that we have our ID, we can use it to create an update or delete the record. Right now, let's create an update by changing her email address. So, to do that we're going to do a couple things. First thing we're going to change the operation to be lead update, we're then going to pass ID as one of the one of the keys. One second… cool, let's delete the other information that we're not trying to update and let's give our new email address- let's say it's, email addresses at new job. In the response we're just going to say that, “Okay if the update was successful all we want back is the update email address.” And now if we run this perfect the email address was updated.
So, let's take this one step farther now and say that we actually want to delete Jessica's record. So, we're going to copy the ID one more time, let's delete the data and then we can see in here- one second… lead delete is the new operation and we're going to pass it, rid of this, get rid of it, data and ID. If Jessica had any related records that belonged to her in the work mandatory relationship, we could pass the force flag which would cascade the delete operation. However, now we're just going to specify okay on delete we just went back the success response to whether or not just go is successfully deleted. So, if we run this now and boom, the record was deleted.
When it comes to defining relationships or connecting records or disassociating records, there's a lot of really cool things that you can do as well. We're going to cover a lot of those in another video, however what I do want to show you is that here in the documentation Explorer, if you were going to go to the Mutation category and look up our lead table- we can see all the different Mutation operations that you have available to you. So, for example, if we wanted to do a lead create many, we can see that okay type lead-many responds and it accepts the argument of data which is a lead-create-many input. Of we were to look at that we could see that it would be an array of the fields name, email and phone number.
So, hopefully you found this video helpful and kind of giving you a jump start on using Mutations. Like I said we're going to go over more advanced Mutations in a subsequent video. However, if you have any questions please feel free to use the comment thread below as well as reach out if you would like any support and helping you get started in 8base. Speak soon.