graphql
Version:
A Query Language and Runtime which can target any service.
47 lines (38 loc) • 1.48 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");
/**
* Copyright (c) 2015-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*
*/
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]));
}
}
};
}