Skip to content

Commit

Permalink
improve(types): readable result types (#1183)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonkuhrt authored Oct 14, 2024
1 parent 61b6f50 commit c14b3d0
Show file tree
Hide file tree
Showing 20 changed files with 1,181 additions and 851 deletions.
7 changes: 6 additions & 1 deletion src/layers/2_Select/SelectAlias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ export type SelectAlias<$SelectionSet = AnyExceptAlias> =
| SelectAliasOne<$SelectionSet>
| SelectAliasMultiple<$SelectionSet>

export type SelectAliasOne<$SelectionSet = AnyExceptAlias> = [alias: string, selectionSet: $SelectionSet]
// dprint-ignore
export type SelectAliasOne<$SelectionSet = AnyExceptAlias> =
[
alias: string,
selectionSet: $SelectionSet
]

export type SelectAliasMultiple<$SelectionSet = AnyExceptAlias> = [
...SelectAliasOne<$SelectionSet>[],
Expand Down
16 changes: 8 additions & 8 deletions src/layers/2_Select/selectionSet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ import type { Indicator } from './Indicator/__.js'
import { type SelectAlias } from './SelectAlias.js'

export type AnySelectionSet = {
[k: string]: FieldValue
} & SpecialFields

interface SpecialFields extends Directive.$Fields {
// todo - this requires having the schema at runtime to know which fields to select.
// $scalars?: SelectionSet.Indicator
$?: ArgsObject
}
[k: string]: FieldValue | ArgsObject
} // & SpecialFields

// interface SpecialFields extends Directive.$Fields {
// // todo - this requires having the schema at runtime to know which fields to select.
// // $scalars?: SelectionSet.Indicator
// // $?: any // ArgsObject
// }

export type FieldValue = AnySelectionSet | Indicator.Indicator

Expand Down
2 changes: 1 addition & 1 deletion src/layers/3_InferResult/Alias.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ type InferSelectAlias<
> =
$SelectAlias extends Select.SelectAlias.SelectAliasOne ? InferSelectAliasOne<$SelectAlias, $FieldName, $Schema, $Node> :
$SelectAlias extends Select.SelectAlias.SelectAliasMultiple ? InferSelectAliasMultiple<$SelectAlias, $FieldName, $Schema, $Node> :
never
never

type InferSelectAliasMultiple<
$SelectAliasMultiple extends Select.SelectAlias.SelectAliasMultiple,
Expand Down
8 changes: 6 additions & 2 deletions src/layers/3_InferResult/__.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ AssertEqual<$<{ interfaceWithArgs: { $:{id:'abc'}; id: true }}>, { interfaceWith
// todo alias on interfaces, interface fragments
// Alias
// scalar
AssertEqual<$<{ id: ['id2', true] }>, { id2: null | string }>()
AssertEqual<$<{ idNonNull: ['id2', true] }>, { id2: string }>()
AssertEqual<$<{ id: ['x', true] }>, { x: null | string }>()
AssertEqual<$<{ idNonNull: ['x', true] }>, { x: string }>()
// object
AssertEqual<$<{ object: ['x', { id: true }] }>, { x: { id: null|string } | null }>()
// argument
AssertEqual<$<{objectWithArgs: ['x', { $: {id:''}; id:true }]}>, { x: { id: null|string } | null }>()
// multi
AssertEqual<$<{ id: [['id1', true],['id2', true]] }>, { id1: null | string; id2: null | string }>()
// AssertEqual<RS<{ id_as: true }>, { id_as: InferResult.Errors.UnknownFieldName<'id_as', Schema.Root.Query> }>()
Expand Down
Loading

0 comments on commit c14b3d0

Please sign in to comment.