UNPKG

927 BJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3exports.GraphQLTimestamp = void 0;
4const graphql_1 = require("graphql");
5exports.GraphQLTimestamp = new graphql_1.GraphQLScalarType({
6 name: 'Timestamp',
7 description: '`Date` type as integer. Type represents date and time as number of milliseconds from start of UNIX epoch.',
8 serialize(value) {
9 return value instanceof Date ? value.getTime() : null;
10 },
11 parseValue(value) {
12 try {
13 return value !== null ? new Date(value) : null;
14 }
15 catch {
16 return null;
17 }
18 },
19 parseLiteral(ast) {
20 if (ast.kind === graphql_1.Kind.INT) {
21 const num = parseInt(ast.value, 10);
22 return new Date(num);
23 }
24 else if (ast.kind === graphql_1.Kind.STRING) {
25 return this.parseValue(ast.value);
26 }
27 return null;
28 },
29});