Schema discovery
Explore an unfamiliar GraphQL API before writing operations.
GraphQL · Function
GraphQL introspection lets clients query an API’s schema itself. The __schema field exposes schema-level information, while related introspection fields reveal type details and runtime type names.
GraphQL exposes schema metadata through introspection fields. Query __schema from the query root to inspect the root operation types and the types defined by the service; query __type when you need details for one named type.
query { __schema { ... } }A response containing the schema metadata selected through the __schema introspection field.
query IntrospectSchema {
__schema {
queryType { name }
types { name kind }
}
}Run this query against a GraphQL endpoint to discover the query root and the schema's available types.
Explore an unfamiliar GraphQL API before writing operations.
Build GraphQL IDE features such as autocomplete and documentation panels.
Generate reference documentation from types, fields, and descriptions.
A client can query the __schema field on the query root to obtain information about the GraphQL service's schema. The result can include operation root types and the schema's types, fields, arguments, and descriptions.
Follow-up: How would you inspect one specific type? Query __type with the type's name, then select the metadata needed from the returned __Type value.
__typename is a meta-field that returns the concrete object type at the current response location. It can be selected for Object, Interface, and Union types, while __schema describes the schema itself.
Follow-up: Why is __typename useful with abstract types? It lets clients identify the concrete runtime type and choose the matching fragment.
Introspection queries are special queries for learning about an API's schema, including its types, fields, and descriptions. This metadata also helps power GraphQL development tools.
Follow-up: What tooling can schema metadata support? It can drive documentation and client or development-tool behavior without separately maintained type descriptions.
__schema__type__typename__Schema__Type