import { GraphQLError } from '../../../error/GraphQLError';
import type { FieldNode } from '../../../language/ast';
import type { ASTVisitor } from '../../../language/visitor';
import { getNamedType } from '../../../type/definition';
import { isIntrospectionType } from '../../../type/introspection';
import type { ValidationContext } from '../../ValidationContext';
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 },
),
);
}
},
};
}