graphql
Version:
A Query Language and Runtime which can target any service.
40 lines (30 loc) • 1.29 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.nonInputTypeOnVarMessage = nonInputTypeOnVarMessage;
exports.VariablesAreInputTypes = VariablesAreInputTypes;
var _GraphQLError = require("../../error/GraphQLError");
var _printer = require("../../language/printer");
var _definition = require("../../type/definition");
var _typeFromAST = require("../../utilities/typeFromAST");
function nonInputTypeOnVarMessage(variableName, typeName) {
return "Variable \"$".concat(variableName, "\" cannot be non-input type \"").concat(typeName, "\".");
}
/**
* Variables are input types
*
* A GraphQL operation is only valid if all the variables it defines are of
* input types (scalar, enum, or input object).
*/
function VariablesAreInputTypes(context) {
return {
VariableDefinition: function VariableDefinition(node) {
var type = (0, _typeFromAST.typeFromAST)(context.getSchema(), node.type); // If the variable type is not an input type, return an error.
if (type && !(0, _definition.isInputType)(type)) {
var variableName = node.variable.name.value;
context.reportError(new _GraphQLError.GraphQLError(nonInputTypeOnVarMessage(variableName, (0, _printer.print)(node.type)), node.type));
}
}
};
}