UNPKG

1.1 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.VariablesAreInputTypesRule = VariablesAreInputTypesRule;
7
8var _GraphQLError = require("../../error/GraphQLError.js");
9
10var _printer = require("../../language/printer.js");
11
12var _definition = require("../../type/definition.js");
13
14var _typeFromAST = require("../../utilities/typeFromAST.js");
15
16/**
17 * Variables are input types
18 *
19 * A GraphQL operation is only valid if all the variables it defines are of
20 * input types (scalar, enum, or input object).
21 */
22function VariablesAreInputTypesRule(context) {
23 return {
24 VariableDefinition: function VariableDefinition(node) {
25 var type = (0, _typeFromAST.typeFromAST)(context.getSchema(), node.type);
26
27 if (type && !(0, _definition.isInputType)(type)) {
28 var variableName = node.variable.name.value;
29 var typeName = (0, _printer.print)(node.type);
30 context.reportError(new _GraphQLError.GraphQLError("Variable \"$".concat(variableName, "\" cannot be non-input type \"").concat(typeName, "\"."), node.type));
31 }
32 }
33 };
34}