Skip to content

Commit e7eb73b

Browse files
avalletesoedirgo
authored andcommitted
chore: reproduce invalid node type error
1 parent c995e4c commit e7eb73b

File tree

3 files changed

+42
-206
lines changed

3 files changed

+42
-206
lines changed

src/select-query-parser/result.ts

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ export type ProcessNode<
197197
RelationName extends string,
198198
Relationships extends GenericRelationship[],
199199
NodeType extends Ast.Node
200-
> = NodeType['type'] extends Ast.StarNode['type'] // If the selection is *
200+
> = NodeType extends Ast.StarNode // If the selection is *
201201
? Row
202-
: NodeType['type'] extends Ast.SpreadNode['type'] // If the selection is a ...spread
203-
? ProcessSpreadNode<Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.SpreadNode>>
204-
: NodeType['type'] extends Ast.FieldNode['type']
205-
? ProcessFieldNode<Schema, Row, RelationName, Relationships, Extract<NodeType, Ast.FieldNode>>
206-
: SelectQueryError<'Unsupported node type.'>
202+
: NodeType extends Ast.SpreadNode // If the selection is a ...spread
203+
? ProcessSpreadNode<Schema, Row, RelationName, Relationships, NodeType>
204+
: NodeType extends Ast.FieldNode
205+
? ProcessFieldNode<Schema, Row, RelationName, Relationships, NodeType>
206+
: SelectQueryError<'Unsupported node type.' & { nodeType: NodeType }>
207207

208208
/**
209209
* Processes a FieldNode and returns the resulting TypeScript type.
@@ -369,7 +369,10 @@ type ProcessSpreadNode<
369369
/**
370370
* Helper type to process the result of a spread node.
371371
*/
372-
type ProcessSpreadNodeResult<Result> = Result extends Record<string, SelectQueryError<string>>
372+
type ProcessSpreadNodeResult<Result> = Result extends Record<
373+
string,
374+
SelectQueryError<string> | null
375+
>
373376
? Result
374377
: ExtractFirstProperty<Result> extends infer SpreadedObject
375378
? ContainsNull<SpreadedObject> extends true

test/select-query-parser/result.test-d.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,35 @@ type SelectQueryFromTableResult<
8686
}
8787
expectType<TypeEqual<typeof result, typeof expected>>(true)
8888
}
89+
90+
{
91+
let result: SelectQueryFromTableResult<
92+
'users',
93+
`msgs:messages(id, ...channels(id, ...channel_details(id, missing_col)))`
94+
>
95+
let expected: {
96+
msgs: {
97+
id: number
98+
channel_details: SelectQueryError<"column 'missing_col' does not exist on 'channel_details'."> | null
99+
}[]
100+
}
101+
expectType<TypeEqual<typeof result, typeof expected>>(true)
102+
}
103+
104+
{
105+
let result1: SelectQueryFromTableResult<
106+
'users',
107+
`msgs:messages(...channels(slug, channel_details!inner(id, details, channel:channels(*))))`
108+
>
109+
let result2: SelectQueryFromTableResult<
110+
'users',
111+
`msgs:messages(...channels(slug, channel_details!inner(channel:channels(*), id, details)))`
112+
>
113+
let result3: SelectQueryFromTableResult<
114+
'users',
115+
`msgs:messages(...channels!inner(slug, channel_details!inner(id, details, channel:channels(*))))`
116+
>
117+
// All variations should not change the result
118+
expectType<typeof result1>(result2!)
119+
expectType<typeof result2>(result3!)
120+
}

test/select-query-parser/types.test-d.ts

Lines changed: 0 additions & 199 deletions
This file was deleted.

0 commit comments

Comments
 (0)