Become a member
to unlock all features

Level Up!

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


    Query a List of Objects with GraphQL


    Now that we understand how to write a simple query to check a total value, we're going to write a query to return a list of pet objects. Along the way, we'll learn a bit more about the GraphQL query language, tackling vocabulary like selection sets and fields. All of the queries are sent to the Pet Library API.



    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: Let's add onto our query a bit and request some data about the pets that are available at the pet library. If I wanted a list of all of our pets, I'm going to query the allPets field. I'll open up our curly braces to select name and weight for each of these pets, and then I'll click play.

    I'll see that allPets returns an array of pets with name and weight for each of them. Also, if I collapse the allPets field, we'll see that totalPets is also being sent in the query, and we get that data as well.

    If we take a closer look at the query, everything wrapped with curly braces is called a selection set. Each piece of data that we're requesting is called a field. I can also add comments to the query by using the pound sign or hashtag.

    Then if I were to use this on one of the fields, we'll see that name is now removed from the query and is not returned.