UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

32 lines (31 loc) 1.25 kB
/** @category Validation Rules */ import type { ASTVisitor } from "../../language/visitor.js"; import type { ValidationContext } from "../ValidationContext.js"; /** * Known Operation Types * * A GraphQL document is only valid if when it contains an operation, * the root type for the operation exists within the schema. * * See https://spec.graphql.org/draft/#sec-Operation-Type-Existence * @param context - The validation context used while checking the document. * @returns A visitor that reports validation errors for this rule. * @example * ```ts * import { parse } from 'graphql/language'; * import { buildSchema } from 'graphql/utilities'; * import { validate, KnownOperationTypesRule } from 'graphql/validation'; * * const schema = buildSchema(` * type Query { * greeting: String * } * `); * const invalidDocument = parse('mutation { greeting }'); * const validDocument = parse('{ greeting }'); * * validate(schema, invalidDocument, [KnownOperationTypesRule])[0].message; // => 'The mutation operation is not supported by the schema.' * validate(schema, validDocument, [KnownOperationTypesRule]); // => [] * ``` */ export declare function KnownOperationTypesRule(context: ValidationContext): ASTVisitor;