UNPKG

ontotext-platform-custom-scalars

Version:
45 lines (35 loc) 1.25 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _graphql = require("graphql"); var _Utilities = require("./Utilities"); /** * Defines custom GraphQLScalarType for negative Integer values. */ var _default = new _graphql.GraphQLScalarType({ name: "NegativeInteger", description: "Negative 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, below zero.")); } return value + ''; } }); exports["default"] = _default;