Course contentsShow
← Web Development
Lesson 1529 of 2,98228. GraphQL FundamentalsFree lesson

Introspection

Querying the GraphQL schema itself to discover available types, fields, and documentation.

Introspection

You'll learn how GraphQL lets you query its own schema to discover types, fields, and documentation on the fly.

What Is Introspection?

Introspection is GraphQL's built-in ability to describe itself. Just as you'd query for user data, you can query the GraphQL schema to ask "What types do you have?", "What fields are on this type?", or "What arguments does this field accept?"

Think of it like asking a library's card catalog about the catalog itself—you're not looking up books, you're discovering what categories, genres, and metadata the catalog tracks.

Why It Matters

Introspection powers tools like GraphiQL and GraphQL Playground. When you open these interfaces and see autocomplete suggestions, type hints, and documentation panels, that's introspection at work. The tool doesn't have hardcoded knowledge of your API—it queries the schema and builds those helpful features dynamically.

How It Works

GraphQL exposes special fields starting with __ (double underscore). The most common is __schema, which returns information about all types, queries, and mutations. Another is __type, which lets you inspect a specific type by name.

Every time you send a query, you could technically include introspection fields to learn about the schema structure:

{
  __schema {
    types {
      name
    }
  }
}

This query lists all available types in the schema. You can drill deeper to see fields, arguments, and even inline documentation written in the schema definition.

Practical Use

Introspection enables dynamic tooling, automatic documentation generation, and client code generation. It's why GraphQL feels self-documenting—the schema is the documentation, and you can query it.

Key Takeaway: Introspection lets you query a GraphQL schema to discover its structure, types, and documentation, powering developer tools and making APIs self-documenting.