12 Days of Baddass Courses sale! Get instant access to the entire egghead library of courses and lessons for 58% off.

Runs out in:
15 : 05 : 52 : 28
Join egghead, unlock knowledge.

Want more egghead? It's 58% off for a limited time only!

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

Unlock All Content for 40% Off
Become a member
to unlock all features

    Send a Nested GraphQL Query

    Eve PorcelloEve Porcello

    In addition to returning lists or scalar values, it’s possible to return GraphQL objects from fields. In this lesson, we’ll take a closer look at the Photo type and how it can be used to store more complex data types.

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



    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




    Instructor: I'd like to adjust this query to include a photo. I want to return a photo for each of these pets. Let's see if there's anything in the schema that'll help us out with that.

    I'm going to search for photo using this search box at the top. I can select photo. It looks like photo is an object. The photo type has fields for full-size image and thumbnail-size image, both of which are strings. Each pet would have a photo.

    If I query photo, it gives me this error message that says, "Field photo of type photo must have a selection of subfields." Because photo is an object, I'm going to need to add another selection set here.

    This allows us to have some flexibility when we are sending a query. A photo may have more than one field associated with it. Then we can request just the fields that we want with our GraphQL query.