Skip to content

Commit

Permalink
better handle check
Browse files Browse the repository at this point in the history
  • Loading branch information
AlecAivazis committed Mar 28, 2024
1 parent 7e58bea commit 4b6578b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
21 changes: 21 additions & 0 deletions packages/houdini/src/lib/router/manifest.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => (
<div>
<h1>{title}</h1>
<p>{content}</p>
</div>
);
export default MyComponent;
`,
expected: ['title'],
},
{
name: 'Functional component with function expression',
source: `
Expand Down
14 changes: 13 additions & 1 deletion packages/houdini/src/lib/router/manifest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -387,5 +387,17 @@ export async function extractQueries(source: string): Promise<string[]> {
return []
}

return props.filter((p) => p !== 'children' && !p.endsWith('$handle'))
return props.reduce<string[]>((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])
}, [])
}

0 comments on commit 4b6578b

Please sign in to comment.