Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/scalars/BigInt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,10 @@ export const GraphQLBigIntConfig: GraphQLScalarTypeConfig<
extensions: {
codegenScalarType: 'bigint',
jsonSchema: {
type: 'integer',
format: 'int64',
// Not format: 'int64' — a BigInt is arbitrary-precision, not 64-bit-bounded,
// and it serializes as a number when within the safe-integer range or as a
// decimal string when larger (to avoid precision loss).
oneOf: [{ type: 'integer' }, { type: 'string', pattern: '^-?\\d+$' }],
},
},
};
Expand Down
5 changes: 4 additions & 1 deletion src/scalars/LocalDateTime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,10 @@ export const LocalDateTimeConfig: GraphQLScalarTypeConfig<string, string> = /*#_
jsonSchema: {
title: 'LocalDateTime',
type: 'string',
format: 'date-time',
// Not format: 'date-time' — RFC 3339 date-time mandates a timezone offset,
// but a LocalDateTime is intentionally offset-less. Match what the scalar
// actually validates, like LocalDate/LocalTime do.
pattern: LOCAL_DATE_TIME_REGEX.source,
},
},
};
Expand Down
7 changes: 5 additions & 2 deletions src/scalars/PostalCode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,11 @@ export const GraphQLPostalCode = /*#__PURE__*/ new GraphQLScalarType({
codegenScalarType: 'string',
jsonSchema: {
title: 'PostalCode',
oneOf: POSTAL_CODE_REGEXES.map(regex => ({
type: 'string',
type: 'string',
// anyOf, not oneOf: postal-code formats overlap across countries (e.g. a
// 5-digit code matches US, DE, FR, IT, ES, ... at once), so a valid code
// matches several patterns — oneOf would require it to match exactly one.
anyOf: POSTAL_CODE_REGEXES.map(regex => ({
pattern: regex.source,
})),
},
Expand Down
4 changes: 2 additions & 2 deletions src/scalars/Timestamp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ export const GraphQLTimestamp = /*#__PURE__*/ new GraphQLScalarType({
extensions: {
codegenScalarType: 'Date | string | number',
jsonSchema: {
type: 'string',
format: 'unix-time',
// serialize() returns a number of milliseconds (Date#getTime), not a string.
type: 'integer',
},
},
});
4 changes: 3 additions & 1 deletion src/scalars/USCurrency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,9 @@ export const GraphQLUSCurrency = /*#__PURE__*/ new GraphQLScalarType({
jsonSchema: {
title: 'USCurrency',
type: 'string',
pattern: '^\\$[0-9]+(\\.[0-9]{2})?$',
// Matches the serialized toLocaleString form: optional leading minus, '$',
// grouped thousands and always two decimals — e.g. $21.25 or -$1,000.00.
pattern: '^-?\\$[0-9]{1,3}(,[0-9]{3})*\\.[0-9]{2}$',
},
},
});
16 changes: 11 additions & 5 deletions src/scalars/ssn/SE.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,14 @@ import { createGraphQLError } from '../../error.js';
// Algorithm:
// https://swedish.identityinfo.net/personalidentitynumber

const SESSN_PATTERNS = ['YYYYMMDDXXXX', 'YYMMDDXXXX'];
// Structural patterns for the two accepted personnummer forms. Full validation
// (date + Luhn checksum) lives in _isValidSwedishPersonalNumber; these only
// describe the string shape for the jsonSchema. An optional -/+ separator is
// allowed since non-digits are stripped before validation.
const SESSN_PATTERNS = [
/^\d{8}[-+]?\d{4}$/, // YYYYMMDD(-)XXXX — 12 digits
/^\d{6}[-+]?\d{4}$/, // YYMMDD(-)XXXX — 10 digits
];

function _isValidSwedishPersonalNumber(value: string): boolean {
// Remove any non-digit characters
Expand Down Expand Up @@ -128,10 +135,9 @@ export const GraphQLSESSN: GraphQLScalarType = /*#__PURE__*/ new GraphQLScalarTy
codegenScalarType: 'string',
jsonSchema: {
title: 'SESSN',
oneOf: SESSN_PATTERNS.map((pattern: string) => ({
type: 'string',
length: pattern.length,
pattern,
type: 'string',
anyOf: SESSN_PATTERNS.map(pattern => ({
pattern: pattern.source,
})),
},
},
Expand Down