From e206a8a8af0c4742a95e6b8d1d095c3a64602eae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behl=C3=BCl=20U=C3=A7ar?= Date: Sun, 12 Nov 2023 20:42:46 -0500 Subject: [PATCH 1/4] always serialize date as only date, stripping time i.e. if 1954-08-21T04:00:00.000Z comes from backend, send that to front-end as 1954-08-21 still. --- src/scalars/iso-date/Date.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scalars/iso-date/Date.ts b/src/scalars/iso-date/Date.ts index f80f8a928..13b56b5d3 100644 --- a/src/scalars/iso-date/Date.ts +++ b/src/scalars/iso-date/Date.ts @@ -27,7 +27,7 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR throw createGraphQLError('Date cannot represent an invalid Date instance'); } else if (typeof value === 'string') { if (validateDate(value)) { - return value; + return serializeDate(value); } throw createGraphQLError(`Date cannot represent an invalid date-string ${value}.`); } else { From 50a0fc3fc5041fd2b742438eb807891a720dec1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behl=C3=BCl=20U=C3=A7ar?= Date: Sun, 12 Nov 2023 20:44:04 -0500 Subject: [PATCH 2/4] increment version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9f4e4f8a8..ae3371981 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "graphql-scalars", - "version": "1.22.4", + "version": "1.22.5", "type": "module", "description": "A collection of scalar types not included in base GraphQL.", "repository": { From 4bef984627ddee7465ba1d4e6b3d5a85d891fb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behl=C3=BCl=20U=C3=A7ar?= Date: Sun, 12 Nov 2023 20:53:41 -0500 Subject: [PATCH 3/4] fix type issue --- src/scalars/iso-date/Date.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scalars/iso-date/Date.ts b/src/scalars/iso-date/Date.ts index 13b56b5d3..ea4cdf69f 100644 --- a/src/scalars/iso-date/Date.ts +++ b/src/scalars/iso-date/Date.ts @@ -27,7 +27,7 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR throw createGraphQLError('Date cannot represent an invalid Date instance'); } else if (typeof value === 'string') { if (validateDate(value)) { - return serializeDate(value); + return serializeDate(new Date(value)); } throw createGraphQLError(`Date cannot represent an invalid date-string ${value}.`); } else { From d13f984e2a5a393452c5a930c6c338f4c747c14f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Behl=C3=BCl=20U=C3=A7ar?= Date: Sun, 12 Nov 2023 21:05:30 -0500 Subject: [PATCH 4/4] accept datetime as date too, using only the date parts --- src/scalars/iso-date/Date.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/scalars/iso-date/Date.ts b/src/scalars/iso-date/Date.ts index ea4cdf69f..969637ad2 100644 --- a/src/scalars/iso-date/Date.ts +++ b/src/scalars/iso-date/Date.ts @@ -10,7 +10,7 @@ import { GraphQLScalarType, Kind } from 'graphql'; import type { GraphQLScalarTypeConfig } from 'graphql'; import { createGraphQLError } from '../../error.js'; import { parseDate, serializeDate } from './formatter.js'; -import { validateDate, validateJSDate } from './validator.js'; +import { validateDate, validateDateTime, validateJSDate } from './validator.js'; export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PURE__*/ { name: 'Date', @@ -26,7 +26,7 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig = /*#__PUR } throw createGraphQLError('Date cannot represent an invalid Date instance'); } else if (typeof value === 'string') { - if (validateDate(value)) { + if (validateDate(value) || validateDateTime(value)) { return serializeDate(new Date(value)); } throw createGraphQLError(`Date cannot represent an invalid date-string ${value}.`);