UNPKG

@graphql-yoga/plugin-disable-introspection

Version:

Disable Introspection plugin for GraphQL Yoga.

23 lines (22 loc) 783 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.useDisableIntrospection = void 0; const graphql_1 = require("graphql"); const store = new WeakMap(); const useDisableIntrospection = (props) => { return { async onRequest({ request }) { const isDisabled = props?.isDisabled ? await props.isDisabled(request) : true; store.set(request, isDisabled); }, onValidate({ addValidationRule, context }) { const isDisabled = store.get(context.request) ?? true; if (isDisabled) { addValidationRule(graphql_1.NoSchemaIntrospectionCustomRule); } }, }; }; exports.useDisableIntrospection = useDisableIntrospection;