1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.NoUndefinedVariablesRule = NoUndefinedVariablesRule;
|
7 |
|
8 | var _GraphQLError = require("../../error/GraphQLError.js");
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 | function NoUndefinedVariablesRule(context) {
|
17 | var variableNameDefined = Object.create(null);
|
18 | return {
|
19 | OperationDefinition: {
|
20 | enter: function enter() {
|
21 | variableNameDefined = Object.create(null);
|
22 | },
|
23 | leave: function leave(operation) {
|
24 | var usages = context.getRecursiveVariableUsages(operation);
|
25 |
|
26 | for (var _i2 = 0; _i2 < usages.length; _i2++) {
|
27 | var _ref2 = usages[_i2];
|
28 | var node = _ref2.node;
|
29 | var varName = node.name.value;
|
30 |
|
31 | if (variableNameDefined[varName] !== true) {
|
32 | context.reportError(new _GraphQLError.GraphQLError(operation.name ? "Variable \"$".concat(varName, "\" is not defined by operation \"").concat(operation.name.value, "\".") : "Variable \"$".concat(varName, "\" is not defined."), [node, operation]));
|
33 | }
|
34 | }
|
35 | }
|
36 | },
|
37 | VariableDefinition: function VariableDefinition(node) {
|
38 | variableNameDefined[node.variable.name.value] = true;
|
39 | }
|
40 | };
|
41 | }
|