Discover a remote schema
A schema-aware client needs to learn an endpoint’s available types and fields before generating requests.
GraphQL · Function
getIntrospectionQuery returns a standard GraphQL query string that asks an endpoint for schema metadata. Clients can send it to discover the API’s types, fields, descriptions, and other introspection information.
getIntrospectionQuery creates a GraphQL query document that requests schema metadata through the introspection system. A client can send the resulting string to an endpoint and use the response with GraphQL tooling, such as schema construction or code generation.
getIntrospectionQuery(options?: IntrospectionOptions): stringA GraphQL query string for retrieving schema information through introspection.
__schema field on the query root.import { getIntrospectionQuery, buildClientSchema } from "graphql";
const query = getIntrospectionQuery();
const response = await fetch("https://example.com/graphql", {
method: "POST",
headers: { "content-type": "application/json" },
body: JSON.stringify({ query }),
});
const { data } = await response.json();
const schema = buildClientSchema(data);
console.log(schema.getQueryType()?.name);Builds the standard introspection document, sends it to a GraphQL endpoint, and converts the returned introspection data into a client schema.
A schema-aware client needs to learn an endpoint’s available types and fields before generating requests.
Development tools need server metadata to provide autocomplete, validation, documentation, or schema exploration.
A build step needs server schema data to construct a client schema or generate typed artifacts.
getIntrospectionQuery do?It generates a standard GraphQL introspection query as a string. That query asks the server for schema information, including types, fields, and descriptions, through the introspection system.
Follow-up: What server field does the query ultimately use? The schema is exposed through the __schema field on the query root, with related metadata available through introspection types.
The returned query can be posted to a GraphQL endpoint like any other query. Its response contains schema metadata that client-side tools can inspect or convert into a usable schema representation.
Follow-up: Why is this useful for tooling? Introspection queries help power GraphQL development tools by exposing the API’s supported schema features.
Introspection is not guaranteed to be available in every deployment. Some first-party GraphQL APIs disable introspection outside development, so an introspection-based client must handle rejection or use another schema distribution approach.
Follow-up: Does disabling introspection fully hide the schema? No; the documentation describes it as security through obscurity and recommends broader controls such as trusted documents and authorization.
__schema__type__typename__Schema__Type__TypeKind__Field__InputValue