From 4b6578bb1d80dbb13c7bbed8a94056285aa46a8f Mon Sep 17 00:00:00 2001 From: Alec Aivazis Date: Wed, 27 Mar 2024 20:27:21 -0700 Subject: [PATCH] better handle check --- .../houdini/src/lib/router/manifest.test.ts | 21 +++++++++++++++++++ packages/houdini/src/lib/router/manifest.ts | 14 ++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/packages/houdini/src/lib/router/manifest.test.ts b/packages/houdini/src/lib/router/manifest.test.ts index 2a2b35be8..fb93d091c 100644 --- a/packages/houdini/src/lib/router/manifest.test.ts +++ b/packages/houdini/src/lib/router/manifest.test.ts @@ -614,6 +614,27 @@ describe('extractQueries', async () => { `, expected: ['title', 'content'], }, + { + name: '$handle', + source: ` + import React from 'react'; + + interface Props { + title: string; + content: string; + } + + const MyComponent = ({ title$handle }: Props) => ( +
+

{title}

+

{content}

+
+ ); + + export default MyComponent; + `, + expected: ['title'], + }, { name: 'Functional component with function expression', source: ` diff --git a/packages/houdini/src/lib/router/manifest.ts b/packages/houdini/src/lib/router/manifest.ts index 0d4d03bd3..781982b50 100644 --- a/packages/houdini/src/lib/router/manifest.ts +++ b/packages/houdini/src/lib/router/manifest.ts @@ -387,5 +387,17 @@ export async function extractQueries(source: string): Promise { return [] } - return props.filter((p) => p !== 'children' && !p.endsWith('$handle')) + return props.reduce((queries, query) => { + // skip the children prop + if (query === 'children') { + return queries + } + + // if the query ends with $handle just use the query name + if (query.endsWith('$handle')) { + query = query.substring(0, query.length - '$handle'.length) + } + + return queries.concat([query]) + }, []) }