From abcda1ae587ef402dc8588b1640a71c722594588 Mon Sep 17 00:00:00 2001 From: Ly Tuan Kiet Date: Mon, 9 Dec 2024 17:24:00 +0700 Subject: [PATCH] refactor: improve DateTime handling in GraphQL builder - Streamlined DateTime serialization and parsing logic in the GraphQL builder for enhanced clarity and maintainability. - Removed commented-out code to reduce clutter and improve code readability. - Ensured consistent error handling for invalid DateTime values. --- src/Graphql/graphql.builder.ts | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Graphql/graphql.builder.ts b/src/Graphql/graphql.builder.ts index 311a600..0034ea9 100644 --- a/src/Graphql/graphql.builder.ts +++ b/src/Graphql/graphql.builder.ts @@ -130,28 +130,24 @@ export class Builder extends SchemaBuilder { this.generator = new PrismaCrudGenerator(this) this.scalarType('DateTime', { serialize: (value) => { - // Serialize outgoing DateTime to ISO string if (typeof value === 'string') { return value } if (typeof value === 'object' && value !== null && 'toISO' in value) { return value } - // if value = Date, convert to DateTime if (value instanceof Date) { return DateTimeUtils.toIsoString(DateTimeUtils.fromDate(value)) } throw new Error('Invalid DateTime') }, parseValue: (value) => { - // Parse incoming ISO string to Luxon DateTime if (typeof value === 'string') { return DateTimeUtils.fromIsoString(value) } throw new Error('Invalid DateTime') }, parseLiteral: (ast) => { - // parse string to DateTime if (ast.kind === Kind.STRING) { return DateTimeUtils.fromIsoString(ast.value) }