graphql
Version:
A Query Language and Runtime which can target any service.
39 lines (38 loc) • 1.19 kB
TypeScript
/** @category Validation Rules */
import type { ASTVisitor } from "../../language/visitor.js";
import type { ASTValidationContext } from "../ValidationContext.js";
/**
* Implements the max introspection depth validation rule.
* @param context - The validation context used while checking the document.
* @returns A visitor that reports validation errors for this rule.
* @example
* ```ts
* import { buildSchema, parse, validate } from 'graphql';
* import { MaxIntrospectionDepthRule } from 'graphql/validation';
*
* const schema = buildSchema(`
* type Query {
* name: String
* }
* `);
*
* const invalidDocument = parse(`
* { __schema { types { fields { type { fields { type { fields { name } } } } } } } }
* `);
* const invalidErrors = validate(schema, invalidDocument, [
* MaxIntrospectionDepthRule,
* ]);
*
* invalidErrors.length; // => 1
*
* const validDocument = parse(`
* { __schema { queryType { name } } }
* `);
* const validErrors = validate(schema, validDocument, [
* MaxIntrospectionDepthRule,
* ]);
*
* validErrors; // => []
* ```
*/
export declare function MaxIntrospectionDepthRule(context: ASTValidationContext): ASTVisitor;