Files
klz-cables.com/.pnpm-store/v10/files/49/02d61742884c6cb2619bc340d8b208f29c9ea0defa9c8f3b45f3d9584ef538730eb99bfb6bfa8d031f6ccb379a331b940ea75c3022dadeb6d82e5472073637
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

59 lines
2.1 KiB
Plaintext

import { GraphQLScalarType, Kind } from 'graphql';
import { createGraphQLError } from '../error.js';
const LOCAL_DATE_TIME_REGEX = /^((?:(\d{4}-\d{2}-\d{2})T(\d{2}:\d{2}:\d{2}(?:\.\d+)?))(Z|[\+-]\d{2}:\d{2})?)$/;
function validateLocalDateTime(value, ast) {
if (typeof value !== 'string') {
throw createGraphQLError(`Value is not string: ${value}`, ast
? {
nodes: [ast],
}
: undefined);
}
if (!LOCAL_DATE_TIME_REGEX.test(value.toUpperCase())) {
throw createGraphQLError(`LocalDateTime cannot represent an invalid local date-time-string ${value}.`, ast
? {
nodes: [ast],
}
: undefined);
}
const valueAsDate = new Date(value);
const isValidDate = !isNaN(valueAsDate.getTime());
if (!isValidDate) {
throw createGraphQLError(`Value is not a valid LocalDateTime: ${value}`, ast
? {
nodes: [ast],
}
: undefined);
}
return value;
}
export const LocalDateTimeConfig = /*#__PURE__*/ {
name: 'LocalDateTime',
description: 'A local date-time string (i.e., with no associated timezone) in `YYYY-MM-DDTHH:mm:ss` format, e.g. `2020-01-01T00:00:00`.',
serialize(value) {
return validateLocalDateTime(value);
},
parseValue(value) {
return validateLocalDateTime(value);
},
parseLiteral(ast) {
if (ast.kind !== Kind.STRING) {
throw createGraphQLError(`Can only validate strings as local date-times but got a: ${ast.kind}`, {
nodes: [ast],
});
}
return validateLocalDateTime(ast.value, ast);
},
extensions: {
codegenScalarType:
// eslint-disable-next-line no-template-curly-in-string
'`${number}${number}${number}${number}-${number}${number}-${number}${number}T${number}${number}:${number}${number}:${number}${number}`',
jsonSchema: {
title: 'LocalDateTime',
type: 'string',
format: 'date-time',
},
},
};
export const GraphQLLocalDateTime = /*#__PURE__*/ new GraphQLScalarType(LocalDateTimeConfig);