Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

always serialize date as only date, stripping time #2176

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
6 changes: 3 additions & 3 deletions src/scalars/iso-date/Date.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<Date, string> = /*#__PURE__*/ {
name: 'Date',
Expand All @@ -26,8 +26,8 @@ export const GraphQLDateConfig: GraphQLScalarTypeConfig<Date, string> = /*#__PUR
}
throw createGraphQLError('Date cannot represent an invalid Date instance');
} else if (typeof value === 'string') {
if (validateDate(value)) {
return value;
if (validateDate(value) || validateDateTime(value)) {
return serializeDate(new Date(value));
}
throw createGraphQLError(`Date cannot represent an invalid date-string ${value}.`);
} else {
Expand Down