Node.js › GraphQL
What is GraphQL introspection, and why might you want to disable it in a production environment?
IntermediateAnswer
Introspection lets a client query the GraphQL schema itself (available types, fields, and their descriptions), which is what powers developer tools like GraphiQL/Apollo Sandbox for auto-generating documentation and enabling autocomplete -- while extremely useful during development, exposing the full schema in production can reveal internal implementation details (field names hinting at unreleased features, or the overall data model) to anyone who queries it, which is why many teams disable introspection (and the associated playground UI) specifically in production.
const server = new ApolloServer({
typeDefs,
resolvers,
introspection: process.env.NODE_ENV !== 'production', // disabled in production
});Real-world example A company discovers a competitor was able to infer an unreleased feature simply by querying their production GraphQL API's introspection endpoint and noticing new, not-yet-documented fields in the schema, prompting them to disable introspection in production going forward.