Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve(types): readable result types #1183

Merged
merged 4 commits into from
Oct 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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