Search⌘ K
AI Features

Introduction to Schema Introspection

Explore how to use schema introspection in GraphQL to query available types, operations, and mutations. Understand root query types and arguments to better navigate and document GraphQL APIs. This lesson helps you interact with a GraphQL server’s schema and enhance your development workflow.

yIt’s important to check which queries or operations a GraphQL server supports. To accommodate this functionality, GraphQL has an introspection system.

When we’ve designed the type system ourselves, we know which types are available. However, if we haven’t designed it, we could ask GraphQL by querying the __schema. The field is always open on the root type of a query. Let’s ask GraphQL what types are available:

Javascript (babel-node)
{
__schema {
types {
name
}
}
}

Using the query above, we’ll get the following response:

JavaScript (JSX)
{
"data": {
"__schema": {
"types": [
{
"name": "PizzaStatus"
},
{
"name": "Pizza"
},
{
"name": "Int"
},
{
"name": "String"
},
{
"name": "Topping"
},
{
"name": "ToppingInput"
},
{
"name": "Query"
},
{
"name": "Mutation"
},
{
"name": "Boolean"
},
{
"name": "__Schema"
},
{
"name": "__Type"
},
{
"name": "__TypeKind"
},
{
"name": "__Field"
},
{
"name": "__InputValue"
},
{
"name": "__EnumValue"
},
{
"name": "__Directive"
},
{
"name": "__DirectiveLocation"
}
]
}
}
}

Wow, that’s a lot of types! What are they? Let’s put them into groups.

  • Query, Mutation, Pizza, PizzaStatus, Topping, and ToppingInput: These are the ones that we defined in our type system.

  • ...