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
Become a member
to unlock all features

Level Up!

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


    Send a Nested GraphQL Query


    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 Pro 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
    orLog In




    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.