Join egghead, unlock knowledge.

Want more egghead?

This lesson is for members. Join us? Get access to all 3,000+ tutorials + a community with expert developers around the world.

Unlock This Lesson
1×
Become a member
to unlock all features

Level Up!

Access all courses & lessons on egghead today and lock-in your price for life.

Autoplay

    Send a checkOut Mutation with GraphQL as an Authorized User

    Eve PorcelloEve Porcello
    graphqlGraphQL

    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.

    Code

    Code

    Become a Member to view code

    You must be a Member to view code

    Access all courses and lessons, track your progress, gain confidence and expertise.

    Become a Member
    and unlock code for this lesson
    Transcript

    Transcript

    Instructor: 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.

    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.

    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.

    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.

    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.

    Discuss

    Discuss