diff --git a/.changeset/pretty-lobsters-push.md b/.changeset/pretty-lobsters-push.md new file mode 100644 index 0000000000..7cca14b936 --- /dev/null +++ b/.changeset/pretty-lobsters-push.md @@ -0,0 +1,5 @@ +--- +'houdini-svelte': patch +--- + +Invalid integer route paramters get unmarshaled as undefined diff --git a/packages/houdini/src/runtime/lib/scalars.test.ts b/packages/houdini/src/runtime/lib/scalars.test.ts index a4d5a215a2..cd6c4ad5f3 100644 --- a/packages/houdini/src/runtime/lib/scalars.test.ts +++ b/packages/houdini/src/runtime/lib/scalars.test.ts @@ -956,6 +956,18 @@ describe('parseScalar', function () { value: '1', expected: 1, }, + { + title: 'invalid Int', + type: 'Int', + value: '', + expected: undefined, + }, + { + title: 'invalid Float', + type: 'Float', + value: '', + expected: undefined, + }, { title: 'Boolean', type: 'Boolean', diff --git a/packages/houdini/src/runtime/lib/scalars.ts b/packages/houdini/src/runtime/lib/scalars.ts index dbd25c77c9..a383726730 100644 --- a/packages/houdini/src/runtime/lib/scalars.ts +++ b/packages/houdini/src/runtime/lib/scalars.ts @@ -199,8 +199,12 @@ export function isScalar(config: ConfigFile, type: string) { export function parseScalar( config: ConfigFile, type: string, - value: string -): string | number | boolean { + value?: string +): string | number | boolean | undefined { + if (typeof value === 'undefined') { + return undefined + } + if (type === 'Boolean') { return value === 'true' } @@ -211,10 +215,18 @@ export function parseScalar( return value } if (type === 'Int') { - return parseInt(value, 10) + const result = parseInt(value, 10) + if (Number.isNaN(result)) { + return undefined + } + return result } if (type === 'Float') { - return parseFloat(value) + const result = parseFloat(value) + if (Number.isNaN(result)) { + return undefined + } + return result } // if we have a special parse function, use it