Send a checkOut Mutation with GraphQL as an Authorized User

Eve Porcello
InstructorEve Porcello
Share this video with your friends

Social Share Links

Send Tweet
Published 5 years ago
Updated 3 years ago

Once logged in, the user will be able to check out pets with a checkOut mutation. In this lesson, we’ll look at how to send a mutation based on current data.

To follow along with these queries, go to the Pet Library GraphQL Playground.

Instructor: [00:00] The next step I want to take is to actually check out a pet. The checkout mutation takes in an ID of a pet to check out. I need to look at the pets that are currently available and find a pet to check out.

[00:10] I'll send the allPets query with a statusAvailable filter. I'll grab the ID, the name, and the category. Let me scroll down a little bit to find out who I want to check out. I want to check out this stingray called Switchblade.

[00:23] In order to do so, I'm going to need to send S2 as an ID. At this point, I can add one more mutation to our query document. Our mutation is going to be called checkout. We'll give the mutation an operation name of checkout, and we'll use the checkout mutation.

[00:40] We'll pass the ID of S2, and we want to grab details about the pet, so we'll grab their name. Let's also get some details about the customer. The customer is going to be me, but I'll grab my name as well. When I send the checkout mutation, I should see the pet has been checked out, and I see the customer who has checked that pet out.

[01:02] If we look at the checkout mutation, we see that this returns the checkout payload. The checkout payload gives us the entire customer object, the entire pet object, and the checkout date. These custom response objects that we can return for mutations are pretty cool. We're able to grab customer fields, pet details, and the checkout date, all bundled into one object.

David
David
~ 4 years ago

This only shows that a user who is authenticated into the system is authorized to use all resources. I was disappointed as I thought this video would demonstrate authorization but it doesn't.

Eve Porcello
Eve Porcelloinstructor
~ 4 years ago

Hi David, thanks for the feedback. Were you hoping to see authorization by field? What is missing that you'd find useful?

Domenic Fiore
Domenic Fiore
~ 2 years ago

Hi Eve,

All of the pets are checked out, meaning I can't really run this example in the playground. I understand the concept so it's OK but would be nice to be able to try it :)

Eve Porcello
Eve Porcelloinstructor
~ 2 years ago

Hey Domenic! These pets are very popular, I guess! I just did some cleanup on the DB, so you should be good to check out a pet now. You might need to create a new account to do so :) Thanks!

Markdown supported.
Become a member to join the discussionEnroll Today