UNPKG

graphql-scalars

Version:

A collection of scalar types not included in base GraphQL.

32 lines 1.18 kB
"use strict"; // Based on https://github.com/stems/graphql-bigint/ Object.defineProperty(exports, "__esModule", { value: true }); const definition_1 = require("graphql/type/definition"); const kinds_1 = require("graphql/language/kinds"); const coerceBigInt = (value) => { if (typeof BigInt === 'undefined') { const numberStr = value.toString().replace('n', ''); const number = Number(numberStr); if (!Number.isInteger(number)) { throw new Error(`${value} is not an integer!`); } return Number(number); } return BigInt(value); }; function default_1(name = 'BigInt') { return new definition_1.GraphQLScalarType({ name, description: 'The `BigInt` scalar type represents non-fractional signed whole numeric values.', serialize: coerceBigInt, parseValue: coerceBigInt, parseLiteral(ast) { if (ast.kind === kinds_1.Kind.INT || ast.kind === kinds_1.Kind.FLOAT || ast.kind === kinds_1.Kind.STRING) { return coerceBigInt(ast.value); } return null; } }); } exports.default = default_1; //# sourceMappingURL=BigInt.js.map