Files
klz-cables.com/.pnpm-store/v10/files/61/e9dba2907cd2a9504e839530fd7bd9708dc2654e19efca4a21cf92a998344fab82713f861a92db882a9eb3d3e6cdd67079e8be6bd02e7c6d1bd713661842fb
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

63 lines
2.5 KiB
Plaintext

// Based on https://github.com/stems/graphql-bigint/
import { GraphQLScalarType, Kind, print } from 'graphql';
import { createGraphQLError } from '../error.js';
import { serializeObject } from './utilities.js';
const specifiedByURL = 'https://www.ecma-international.org/ecma-262/#sec-number.issafeinteger';
export const GraphQLSafeIntConfig = {
name: 'SafeInt',
description: 'The `SafeInt` scalar type represents non-fractional signed whole numeric values that are ' +
'considered safe as defined by the ECMAScript specification.',
specifiedByURL,
specifiedByUrl: specifiedByURL,
serialize(outputValue) {
const coercedValue = serializeObject(outputValue);
if (typeof coercedValue === 'boolean') {
return coercedValue ? 1 : 0;
}
let num = coercedValue;
if (typeof coercedValue === 'string' && coercedValue !== '') {
num = Number(coercedValue);
}
if (typeof num !== 'number' || !Number.isInteger(num)) {
throw createGraphQLError(`SafeInt cannot represent non-integer value: ${coercedValue}`);
}
if (!Number.isSafeInteger(num)) {
throw createGraphQLError('SafeInt cannot represent unsafe integer value: ' + coercedValue);
}
return num;
},
parseValue(inputValue) {
if (typeof inputValue !== 'number' || !Number.isInteger(inputValue)) {
throw createGraphQLError(`SafeInt cannot represent non-integer value: ${inputValue}`);
}
if (!Number.isSafeInteger(inputValue)) {
throw createGraphQLError(`SafeInt cannot represent unsafe integer value: ${inputValue}`);
}
return inputValue;
},
parseLiteral(valueNode) {
if (valueNode.kind !== Kind.INT) {
throw createGraphQLError(`SafeInt cannot represent non-integer value: ${print(valueNode)}`, {
nodes: valueNode,
});
}
const num = parseInt(valueNode.value, 10);
if (!Number.isSafeInteger(num)) {
throw createGraphQLError(`SafeInt cannot represent unsafe integer value: ${valueNode.value}`, {
nodes: valueNode,
});
}
return num;
},
extensions: {
codegenScalarType: 'number',
jsonSchema: {
title: 'SafeInt',
type: 'integer',
minimum: Number.MIN_SAFE_INTEGER,
maximum: Number.MAX_SAFE_INTEGER,
},
},
};
export const GraphQLSafeInt = /*#__PURE__*/ new GraphQLScalarType(GraphQLSafeIntConfig);