UNPKG

graphql-scalars

Version:

A collection of scalar types not included in base GraphQL.

26 lines 1.11 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 = 'NonNegativeInt') { return new definition_1.GraphQLScalarType({ name, description: 'Integers that will have a value of 0 or more.', serialize(value) { return utilities_1.processValue(value, utilities_1.VALIDATIONS.NonNegativeInt); }, parseValue(value) { return utilities_1.processValue(value, utilities_1.VALIDATIONS.NonNegativeInt); }, parseLiteral(ast) { if (ast.kind !== language_1.Kind.INT) { throw new error_1.GraphQLError(`Can only validate integers as non-negative integers but got a: ${ast.kind}`); } return utilities_1.processValue(ast.value, utilities_1.VALIDATIONS.NonNegativeInt); }, }); } exports.default = default_1; //# sourceMappingURL=NonNegativeInt.js.map