Check out a free preview of the full REST & GraphQL API Design in Node.js, v2 (using Express & MongoDB) course:
The "Exercise: Mutations" Lesson is part of the full, REST & GraphQL API Design in Node.js, v2 (using Express & MongoDB) course featured in this preview video. Here's what you'd learn in this lesson:

Impliment the create, update and remove mutations for Song and Playlist models. - https://github.com/FrontendMasters/api-design-node-v2/tree/lesson-12

Get Unlimited Access Now

Transcript from the "Exercise: Mutations" Lesson

[00:00:03]
>> Scott Moss: Okay, so if you check out to lesson 12, you're gonna be tasked with creating mutations for the song and the playlist. So I should be able to create,
>> Scott Moss: Update, and remove songs and playlists with mutations. And I should be able to see them in my doc.

[00:00:25] So let's go here. Or actually, you can just focus on create and update. If you want some extra credit, you could do delete. But you know how to do delete. Only if you want to feel challenged. So if you go look at the docs. Eventually you should see some mutations in here like this.

[00:00:44] So you should see new song, update song, new playlist, update playlist. And if you went further you would see remove song or remove playlist. So what I want you to do is one, look at what I'm doing in the user mutation. Two, look at what we just did.

[00:00:58] And three, If you get lost and like how do I do this in Mongo. Well, we already did it in the controllers from yesterday. So go look at the controllers to see how we did it there. It's more or less the exact same thing. If that's the block is like I don't how to do this in Mongo and you can figure everything else out in graphql, that's awesome.

[00:01:15] Just go look at the controllers and you can see how we're doing it there or I can walk around and help you but the important part here is like how do I do this in GraphQL? How do I get to the point where I'm only stuck on the actual database part?

[00:01:26] Which is pretty simple, because that means GraphQL did its job. It's not worried about the database. Cool, any questions? So let me pull up the test.
>> Scott Moss: So again the remove ones are for extra credit. Once you create those, you shouldn't have to link up any files or anything.

[00:01:49] It should automatically just reload your graphical. You should see them. Everything's already linked up, so you should be good to go. And so remember you need to scope your mutations in a mutation object like that. Very much like we're doing a query, you need to put them in mutation.

[00:02:04] These are going to be merged together eventually, so it's totally fine to do a mutation. Put your functions on there, be done with it.
>> Scott Moss: Cool. Any other questions?
>> Speaker 2: Lesson 12 then?
>> Scott Moss: This is lesson 12.