UNPKG

ontotext-platform-custom-scalars

Version:
40 lines (31 loc) 1.06 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _graphql = require("graphql"); var _Utilities = require("./Utilities"); var NON_NEGATIVE_FLOAT = 'NonNegativeFloat'; function convert(value) { if (value < 0) { throw new _graphql.GraphQLError("The value of '".concat(NON_NEGATIVE_FLOAT, "' should be positive or zero.")); } return (0, _Utilities.normalizeFloatingPointNumbers)(value); } /** * Defines custom GraphQLScalarType for non negative float values. */ var _default = new _graphql.GraphQLScalarType({ name: NON_NEGATIVE_FLOAT, description: "An Float scalar that must be greater than or equal to zero", 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;