ontotext-platform-custom-scalars
Version:
A library of customized GraphQL scalars for Ontotext Platform
45 lines (35 loc) • 1.26 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = void 0;
var _graphql = require("graphql");
var _Utilities = require("./Utilities");
/**
* Defines custom GraphQLScalarType for non positive Integer values.
*/
var _default = new _graphql.GraphQLScalarType({
name: "NonPositiveInteger",
description: "Non-positive integer (<=0), unlimited digits",
serialize: function serialize(value) {
return (0, _Utilities.parseAsBigNumber)(value, this.name);
},
parseValue: function parseValue(value) {
return (0, _Utilities.parseAsBigNumber)(value, this.name);
},
parseLiteral: function parseLiteral(node) {
var kind = node.kind;
if (_graphql.Kind.INT !== kind && _graphql.Kind.STRING !== kind) {
(0, _Utilities.throwConversionError)(kind, this.name);
}
var value = node.value;
if (!(0, _Utilities.isInteger)(value)) {
throw new _graphql.GraphQLError("Expected '".concat(this.name, "', but got '").concat(value, "'."));
}
if ((0, _Utilities.isPositive)(value) && value !== 0) {
throw new _graphql.GraphQLError("The value of '".concat(this.name, "' should be negative or zero."));
}
return value + '';
}
});
exports["default"] = _default;