🎁

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 : 54 : 05
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
1×
Become a member
to unlock all features
Autoplay

    Query a GraphQL API's Types With Introspection Queries

    Eve PorcelloEve Porcello
    graphqlGraphQL

    Introspection is the ability to query information about a GraphQL API’s schema. In this lesson, we will write queries that will return information about the pet library schema.

    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
    Discuss

    Discuss

    Transcript

    Transcript

    Instructor: Throughout this process, we've used the schema tab to look at all the available queries and types on this API. There's also a way that we can use the query language itself to look at, or introspect, the schema.

    We're going to send some introspection queries to look at the schema for this API. The first thing we're going to query is __schema. This will show us the schema for this server. We can query all of the types on the types query, then let's look at the name, the kind, and the description.

    I'm going to go ahead and click play on this, and we should see all of the different types. Now, let's write a query for just the customer type. We're going to query __type. We're going to use the type name. Let's add customer as a string.

    Then we if want to find out what fields are available on the customer type, we can query fields, name, and description for each. Now, if I look at customer, we see username, name, date created, current pets, all of the fields that we're familiar with, along with their descriptions.

    What if we wanted to ask our schema which queries are available on this API? Let's write another query for availableQueries. We'll look at the schema, and then we'll look at query type. Query type, we want to look at the fields, so what fields are available in that query type.

    Then let's look at the name and the description. We should see, if we click on availableQueries, total pets, available pets, checked out pets, all of the queries on this API. The final query I want to send is for the pet interface.

    Let's write a query for interface types. We're going to look at __type. We'll look for the pet interface. Then we can look for the kind. This will give us the kind, the interface. We're going to figure out the name, the description.

    This should give us the pet and the description for that pet interface. Then finally, if you want to see all of the different implementations of that interface, all you need to do is look at possible types. Then we'll query name, kind, description. There we go. Cat, dog, rabbit, and stingray.