UNPKG

@grapi/server

Version:

Grapi Schema Generator For GraphQL Server

35 lines (34 loc) 1.17 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.DateTime = void 0; const graphql_1 = require("graphql"); const isISO8601_1 = __importDefault(require("validator/lib/isISO8601")); const serialize = (value) => { if ((0, isISO8601_1.default)(value.toISOString())) { return value; } throw new Error('DateTime cannot represent an invalid ISO-8601 Date string'); }; const parseValue = (value) => { if ((0, isISO8601_1.default)(value)) { return new Date(value); } throw new Error('DateTime cannot represent an invalid ISO-8601 Date string'); }; const parseLiteral = (ast) => { if ((0, isISO8601_1.default)(ast.value)) { return new Date(ast.value); } throw new Error('DateTime cannot represent an invalid ISO-8601 Date string'); }; const DateTime = new graphql_1.GraphQLScalarType({ name: 'DateTime', description: 'ISO-8601 encoded UTC date string', serialize, parseValue, parseLiteral, }); exports.DateTime = DateTime;