Lesson 9 / 25

Introspection and Tooling

A self-describing API.

Ask the schema about itself

GraphQL servers support introspection: special fields such as __schema and __type return the types, fields, arguments and descriptions of the API. Tools like GraphiQL, Apollo Sandbox and IDE plugins use it for autocomplete, documentation and validation, and code generators use it to create typed clients. Many teams disable or restrict introspection in production for public APIs and rely on a published schema file instead.

An introspection query

Listing the fields of a type.

query {
  __type(name: "Order") {
    name
    fields {
      name
      type { name kind ofType { name } }
      isDeprecated
      deprecationReason
    }
  }
}

Publish the schema as an artefact

Exporting the SDL in CI lets clients generate types and lets reviewers diff schema changes.

Quick check: What does introspection provide?

  • Server CPU usage
  • Database statistics
  • A description of the schema's types and fields, queried through GraphQL itself
  • User passwords
Answer

A description of the schema's types and fields, queried through GraphQL itself — Powers tooling and docs.