UNPKG

graphql-scalars

Version:

A collection of scalar types not included in base GraphQL.

26 lines 1.15 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const definition_1 = require("graphql/type/definition"); const error_1 = require("graphql/error"); const language_1 = require("graphql/language"); const utilities_1 = require("./utilities"); function default_1(name = 'NonNegativeFloat') { return new definition_1.GraphQLScalarType({ name, description: 'Floats that will have a value of 0 or more.', serialize(value) { return utilities_1.processValue(value, utilities_1.VALIDATIONS.NonNegativeFloat); }, parseValue(value) { return utilities_1.processValue(value, utilities_1.VALIDATIONS.NonNegativeFloat); }, parseLiteral(ast) { if (ast.kind !== language_1.Kind.FLOAT) { throw new error_1.GraphQLError(`Can only validate floating point numbers as non-negative floating point numbers but got a: ${ast.kind}`); } return utilities_1.processValue(ast.value, utilities_1.VALIDATIONS.NonNegativeFloat); }, }); } exports.default = default_1; //# sourceMappingURL=NonNegativeFloat.js.map