UNPKG

ontotext-platform-custom-scalars

Version:
40 lines (31 loc) 1.03 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _graphql = require("graphql"); var _Utilities = require("./Utilities"); var NEGATIVE_FLOAT = 'NegativeFloat'; function convert(value) { if (value >= 0) { throw new _graphql.GraphQLError("The value of '".concat(NEGATIVE_FLOAT, "' should be negative, below zero.")); } return (0, _Utilities.normalizeFloatingPointNumbers)(value); } /** * Defines custom GraphQLScalarType for negative float values. */ var _default = new _graphql.GraphQLScalarType({ name: NEGATIVE_FLOAT, description: "An Float scalar that must be a negative value", serialize: function serialize(value) { return convert(_graphql.GraphQLFloat.serialize(value)); }, parseValue: function parseValue(value) { return convert(_graphql.GraphQLFloat.parseValue(value)); }, parseLiteral: function parseLiteral(node) { return convert(_graphql.GraphQLFloat.parseLiteral(node)); } }); exports["default"] = _default;