Skip to content

Commit c14b3d0

Browse files
authored
improve(types): readable result types (#1183)
1 parent 61b6f50 commit c14b3d0

File tree

20 files changed

+1181
-851
lines changed

20 files changed

+1181
-851
lines changed

src/layers/2_Select/SelectAlias.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ export type SelectAlias<$SelectionSet = AnyExceptAlias> =
44
| SelectAliasOne<$SelectionSet>
55
| SelectAliasMultiple<$SelectionSet>
66

7-
export type SelectAliasOne<$SelectionSet = AnyExceptAlias> = [alias: string, selectionSet: $SelectionSet]
7+
// dprint-ignore
8+
export type SelectAliasOne<$SelectionSet = AnyExceptAlias> =
9+
[
10+
alias: string,
11+
selectionSet: $SelectionSet
12+
]
813

914
export type SelectAliasMultiple<$SelectionSet = AnyExceptAlias> = [
1015
...SelectAliasOne<$SelectionSet>[],

src/layers/2_Select/selectionSet.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ import type { Indicator } from './Indicator/__.js'
44
import { type SelectAlias } from './SelectAlias.js'
55

66
export type AnySelectionSet = {
7-
[k: string]: FieldValue
8-
} & SpecialFields
9-
10-
interface SpecialFields extends Directive.$Fields {
11-
// todo - this requires having the schema at runtime to know which fields to select.
12-
// $scalars?: SelectionSet.Indicator
13-
$?: ArgsObject
14-
}
7+
[k: string]: FieldValue | ArgsObject
8+
} // & SpecialFields
9+
10+
// interface SpecialFields extends Directive.$Fields {
11+
// // todo - this requires having the schema at runtime to know which fields to select.
12+
// // $scalars?: SelectionSet.Indicator
13+
// // $?: any // ArgsObject
14+
// }
1515

1616
export type FieldValue = AnySelectionSet | Indicator.Indicator
1717

src/layers/3_InferResult/Alias.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ type InferSelectAlias<
3636
> =
3737
$SelectAlias extends Select.SelectAlias.SelectAliasOne ? InferSelectAliasOne<$SelectAlias, $FieldName, $Schema, $Node> :
3838
$SelectAlias extends Select.SelectAlias.SelectAliasMultiple ? InferSelectAliasMultiple<$SelectAlias, $FieldName, $Schema, $Node> :
39-
never
39+
never
4040

4141
type InferSelectAliasMultiple<
4242
$SelectAliasMultiple extends Select.SelectAlias.SelectAliasMultiple,

src/layers/3_InferResult/__.test-d.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,12 @@ AssertEqual<$<{ interfaceWithArgs: { $:{id:'abc'}; id: true }}>, { interfaceWith
8484
// todo alias on interfaces, interface fragments
8585
// Alias
8686
// scalar
87-
AssertEqual<$<{ id: ['id2', true] }>, { id2: null | string }>()
88-
AssertEqual<$<{ idNonNull: ['id2', true] }>, { id2: string }>()
87+
AssertEqual<$<{ id: ['x', true] }>, { x: null | string }>()
88+
AssertEqual<$<{ idNonNull: ['x', true] }>, { x: string }>()
89+
// object
90+
AssertEqual<$<{ object: ['x', { id: true }] }>, { x: { id: null|string } | null }>()
91+
// argument
92+
AssertEqual<$<{objectWithArgs: ['x', { $: {id:''}; id:true }]}>, { x: { id: null|string } | null }>()
8993
// multi
9094
AssertEqual<$<{ id: [['id1', true],['id2', true]] }>, { id1: null | string; id2: null | string }>()
9195
// AssertEqual<RS<{ id_as: true }>, { id_as: InferResult.Errors.UnknownFieldName<'id_as', Schema.Root.Query> }>()

0 commit comments

Comments
 (0)