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.
Instructor: [00:00] 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.
[00:18] 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.
[00:31] 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.
[00:45] 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.
Each data we're requesting is called a field
Everything wrapped after
query
with curly braces is called a selection set