UNPKG

graphql

Version:

A Query Language and Runtime which can target any service.

21 lines 1.02 kB
import { GraphQLError } from "../../error/GraphQLError.mjs"; export function NoUndefinedVariablesRule(context) { return { OperationDefinition(operation) { const variableNameDefined = new Set(operation.variableDefinitions?.map((node) => node.variable.name.value)); const usages = context.getRecursiveVariableUsages(operation); for (const { node, fragmentVariableDefinition } of usages) { if (fragmentVariableDefinition) { continue; } const varName = node.name.value; if (!variableNameDefined.has(varName)) { context.reportError(new GraphQLError(operation.name ? `Variable "$${varName}" is not defined by operation "${operation.name.value}".` : `Variable "$${varName}" is not defined.`, { nodes: [node, operation] })); } } }, }; } //# sourceMappingURL=NoUndefinedVariablesRule.js.map