UNPKG

894 BJavaScriptView Raw
1import { GraphQLError } from "../../error/GraphQLError.mjs";
2import { print } from "../../language/printer.mjs";
3import { isInputType } from "../../type/definition.mjs";
4import { typeFromAST } from "../../utilities/typeFromAST.mjs";
5
6/**
7 * Variables are input types
8 *
9 * A GraphQL operation is only valid if all the variables it defines are of
10 * input types (scalar, enum, or input object).
11 */
12export function VariablesAreInputTypesRule(context) {
13 return {
14 VariableDefinition: function VariableDefinition(node) {
15 var type = typeFromAST(context.getSchema(), node.type);
16
17 if (type && !isInputType(type)) {
18 var variableName = node.variable.name.value;
19 var typeName = print(node.type);
20 context.reportError(new GraphQLError("Variable \"$".concat(variableName, "\" cannot be non-input type \"").concat(typeName, "\"."), node.type));
21 }
22 }
23 };
24}