@envelop/disable-introspection
Version:
This plugin injects the `NoSchemaIntrospectionCustomRule` validation rule exported from the `graphql` module to the validation phase for disabling introspection.
16 lines (15 loc) • 552 B
JavaScript
import { NoSchemaIntrospectionCustomRule } from 'graphql';
export const useDisableIntrospection = (options) => {
const disableIf = options?.disableIf;
return {
onValidate: disableIf
? ({ addValidationRule, context, params }) => {
if (disableIf({ context, params })) {
addValidationRule(NoSchemaIntrospectionCustomRule);
}
}
: ({ addValidationRule }) => {
addValidationRule(NoSchemaIntrospectionCustomRule);
},
};
};