Files
klz-cables.com/.pnpm-store/v10/files/5a/d1ae68840957f6d2f3d791d70d6fe478b6b99638a368737ca461fac6579b669f471a8c9d9c6bfd7d4885a92e4bbc1ffc9f8afedbdfe416ebb666bc34b1958a
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

43 lines
1.6 KiB
Plaintext

import { GraphQLScalarType, Kind } from 'graphql';
import { createGraphQLError } from '../error.js';
const validate = (value, ast) => {
const parsed = typeof value === 'string' ? parseInt(value, 10) : value;
if (typeof parsed !== 'number' || Number.isNaN(parsed)) {
throw createGraphQLError(`Value is not a number: ${value}`, ast ? { nodes: ast } : undefined);
}
if (parsed === Infinity || parsed === -Infinity) {
throw createGraphQLError(`Value is not a finite number: ${value}`, ast ? { nodes: ast } : undefined);
}
if (parsed <= 0 || parsed > 65535) {
throw createGraphQLError(`Value is not a valid TCP port: ${value}`, ast ? { nodes: ast } : undefined);
}
return parsed;
};
export const GraphQLPort = /*#__PURE__*/ new GraphQLScalarType({
name: `Port`,
description: `A field whose value is a valid TCP port within the range of 0 to 65535: https://en.wikipedia.org/wiki/Transmission_Control_Protocol#TCP_ports`,
serialize(value) {
return validate(value);
},
parseValue(value) {
return validate(value);
},
parseLiteral(ast) {
if (ast.kind !== Kind.INT) {
throw createGraphQLError(`Can only validate integers as TCP ports but got a: ${ast.kind}`, {
nodes: ast,
});
}
return validate(ast.value, ast);
},
extensions: {
codegenScalarType: 'string | number',
jsonSchema: {
title: 'Port',
type: 'integer',
minimum: 0,
maximum: 65535,
},
},
});