import { GraphQLError } from '../../../error/GraphQLError.js';
import type { FieldNode } from '../../../language/ast.js';
import type { ASTVisitor } from '../../../language/visitor.js';
import { getNamedType } from '../../../type/definition.js';
import { isIntrospectionType } from '../../../type/introspection.js';
import type { ValidationContext } from '../../ValidationContext.js';
export function NoSchemaIntrospectionCustomRule(
context: ValidationContext,
): ASTVisitor {
return {
Field(node: FieldNode) {
const type = getNamedType(context.getType());
if (type && isIntrospectionType(type)) {
context.reportError(
new GraphQLError(
`GraphQL introspection has been disabled, but the requested query contained the field "${node.name.value}".`,
{ nodes: node },
),
);
}
},
};
}