Skip to content

Commit fc13916

Browse files
authored
feat: no schema required for document object mapping (#1160)
1 parent 3c0a60c commit fc13916

File tree

90 files changed

+1239
-532
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

90 files changed

+1239
-532
lines changed

examples/20_output/output_return-error_return-error-execution__return-error-execution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ const pokemon = Pokemon
2020

2121
type _result = typeof result
2222
const result = await pokemon.mutation.addPokemon({
23-
$: { name: ``, hp: 1, defense: 0, attack: 0, type: `water` },
23+
$: { name: ``, hp: 1, defense: 0, attack: 0, $type: `water` },
2424
// ^^
2525
name: true,
2626
})

examples/55_generated/generated_document.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ const pokemons = await pokemon.document({
2929
makeSomeNewPokemons: {
3030
addPokemon: [
3131
[`addAngryPikachu`, {
32-
$: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100, type: `electric` },
32+
$: { name: `AngryPikachu`, attack: 100, defense: 100, hp: 100, $type: `electric` },
3333
name: true,
3434
}],
3535
[`addAngryCharizard`, {
36-
$: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100, type: `fire` },
36+
$: { name: `AngryCharizard`, attack: 100, defense: 100, hp: 100, $type: `fire` },
3737
name: true,
3838
}],
3939
],

src/entrypoints/utilities-for-generated.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
export { type Simplify } from 'type-fest'
22
export * from '../layers/2_Select/__.js'
3+
export { type SchemaIndex as SchemaIndexBase } from '../layers/4_generator/generators/SchemaIndex.js'
34
export type {
45
ConfigGetOutputError,
56
ResolveOutputReturnRootField,

src/layers/1_Schema/_.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
export { readMaybeThunk, type RootTypeName } from './core/helpers.js'
2-
export * from './core/Index.js'
32
export * from './core/Named/__.js'
43
export * as Directives from './Directives.js'
54
export * from './Hybrid/__.js'

src/layers/1_Schema/core/Index.ts

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

src/layers/1_Schema/core/helpers.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import type { Index } from './Index.js'
2-
31
export type MaybeThunk<$Type> = $Type | Thunk<$Type>
42

53
export type Thunk<$Type> = () => $Type
@@ -19,4 +17,5 @@ export namespace Base {
1917
}
2018
}
2119

22-
export type RootTypeName = keyof Index['Root']
20+
// todo stop using this, just use the graphql one
21+
export type RootTypeName = 'Query' | 'Mutation' | 'Subscription'

src/layers/2_Select/arguments.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,9 @@ export type ArgValue = string | boolean | null | number | ArgsObject
33
export type ArgsObject = { [k: string]: ArgValue }
44

55
export const key = `$`
6+
7+
export const enumKeyPrefix = `$`
8+
9+
export const enumKeyPrefixPattern = /^\$/g
10+
11+
export const isEnumKey = (key: string) => key.startsWith(enumKeyPrefix)

src/layers/3_ResultSet/infer/Field.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ import type { Simplify } from 'type-fest'
22
import type { TSError } from '../../../lib/TSError.js'
33
import type { Schema } from '../../1_Schema/__.js'
44
import type { Select } from '../../2_Select/__.js'
5+
import type { SchemaIndex } from '../../4_generator/generators/SchemaIndex.js'
56
import type { InferInterface, InferObject, InferUnion } from './root.js'
67

78
// dprint-ignore
8-
export type InferField<$SelectionSet, $Field extends Schema.SomeField, $Schema extends Schema.Index> =
9+
export type InferField<$SelectionSet, $Field extends Schema.SomeField, $Schema extends SchemaIndex> =
910
Simplify<
1011
$SelectionSet extends Select.Directive.Include.FieldStates.Negative | Select.Directive.Skip.FieldStates.Positive ?
1112
null :
@@ -20,7 +21,7 @@ export type InferField<$SelectionSet, $Field extends Schema.SomeField, $Schema e
2021
type InferFieldType<
2122
$SelectionSet,
2223
$Type extends Schema.Output.Any,
23-
$Schema extends Schema.Index
24+
$Schema extends SchemaIndex
2425
> =
2526
$Type extends Schema.__typename<infer $Value> ? $Value :
2627
$Type extends Schema.Output.Nullable<infer $InnerType> ? null | InferFieldType<$SelectionSet, $InnerType, $Schema> :

src/layers/3_ResultSet/infer/SelectAlias.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
import type { mergeObjectArray, ValuesOrEmptyObject } from '../../../lib/prelude.js'
22
import type { Schema } from '../../1_Schema/__.js'
33
import type { Select } from '../../2_Select/__.js'
4+
import type { SchemaIndex } from '../../4_generator/generators/SchemaIndex.js'
45
import type { InferField } from './Field.js'
56

67
// dprint-ignore
78
export type InferSelectionSelectAlias<
89
$SelectionSet,
9-
$Schema extends Schema.Index,
10+
$Schema extends SchemaIndex,
1011
$Node extends Schema.Output.Object$2
1112
> =
1213
ValuesOrEmptyObject<
@@ -30,7 +31,7 @@ export type InferSelectionSelectAlias<
3031
export type InferSelectAlias<
3132
$SelectAlias extends Select.SelectAlias.SelectAlias,
3233
$FieldName extends string,
33-
$Schema extends Schema.Index,
34+
$Schema extends SchemaIndex,
3435
$Node extends Schema.Output.Object$2,
3536
> =
3637
$SelectAlias extends Select.SelectAlias.SelectAliasOne ? InferSelectAliasOne<$SelectAlias, $FieldName, $Schema, $Node> :
@@ -40,7 +41,7 @@ export type InferSelectAlias<
4041
type InferSelectAliasMultiple<
4142
$SelectAliasMultiple extends Select.SelectAlias.SelectAliasMultiple,
4243
$FieldName extends string,
43-
$Schema extends Schema.Index,
44+
$Schema extends SchemaIndex,
4445
$Node extends Schema.Output.Object$2,
4546
> = mergeObjectArray<
4647
{
@@ -51,7 +52,7 @@ type InferSelectAliasMultiple<
5152
type InferSelectAliasOne<
5253
$SelectAliasOne extends Select.SelectAlias.SelectAliasOne,
5354
$FieldName extends string,
54-
$Schema extends Schema.Index,
55+
$Schema extends SchemaIndex,
5556
$Node extends Schema.Output.Object$2,
5657
> = {
5758
[_ in $SelectAliasOne[0]]: InferField<$SelectAliasOne[1], $Node['fields'][$FieldName], $Schema>

src/layers/3_ResultSet/infer/root.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@ import { AssertIsEqual, type ExcludeNull, type GetKeyOr, type StringKeyof } from
22
import type { TSError } from '../../../lib/TSError.js'
33
import type { Schema } from '../../1_Schema/__.js'
44
import type { Select } from '../../2_Select/__.js'
5+
import type { SchemaIndex } from '../../4_generator/generators/SchemaIndex.js'
56
import type { InferField } from './Field.js'
67
import type { InferSelectionSelectAlias } from './SelectAlias.js'
78

89
export type RootViaObject<
910
$SelectionSet,
10-
$Schema extends Schema.Index,
11+
$Schema extends SchemaIndex,
1112
$RootType extends Schema.Output.RootType,
1213
> = InferRoot<
1314
$SelectionSet,
@@ -16,25 +17,25 @@ export type RootViaObject<
1617
>
1718

1819
// dprint-ignore
19-
export type Query<$SelectionSet, $Schema extends Schema.Index> =
20+
export type Query<$SelectionSet, $Schema extends SchemaIndex> =
2021
InferRoot<$SelectionSet, $Schema, 'Query'>
2122

2223
// dprint-ignore
23-
export type Mutation<$SelectionSet, $Schema extends Schema.Index> =
24+
export type Mutation<$SelectionSet, $Schema extends SchemaIndex> =
2425
InferRoot<$SelectionSet, $Schema, 'Mutation'>
2526

2627
// dprint-ignore
27-
export type Subscription<$SelectionSet, $Schema extends Schema.Index> =
28+
export type Subscription<$SelectionSet, $Schema extends SchemaIndex> =
2829
InferRoot<$SelectionSet, $Schema, 'Subscription'>
2930

3031
export type InferRoot<
3132
$SelectionSet,
32-
$Schema extends Schema.Index,
33+
$Schema extends SchemaIndex,
3334
$RootTypeName extends Schema.RootTypeName,
3435
> = InferObject<$SelectionSet, $Schema, ExcludeNull<$Schema['Root'][$RootTypeName]>>
3536

3637
// dprint-ignore
37-
export type InferObject<$SelectionSet, $Schema extends Schema.Index, $Node extends Schema.Output.Object$2> =
38+
export type InferObject<$SelectionSet, $Schema extends SchemaIndex, $Node extends Schema.Output.Object$2> =
3839
Select.SelectScalarsWildcard.IsSelectScalarsWildcard<$SelectionSet> extends true
3940
// todo what about when scalars wildcard is combined with other fields like relations?
4041
? InferSelectScalarsWildcard<$SelectionSet, $Schema,$Node>
@@ -45,7 +46,7 @@ export type InferObject<$SelectionSet, $Schema extends Schema.Index, $Node exten
4546
)
4647

4748
// dprint-ignore
48-
type InferSelectionNonSelectAlias<$SelectionSet , $Schema extends Schema.Index, $Node extends Schema.Output.Object$2> =
49+
type InferSelectionNonSelectAlias<$SelectionSet , $Schema extends SchemaIndex, $Node extends Schema.Output.Object$2> =
4950
{
5051
[$Select in PickSelectsPositiveIndicatorAndNotSelectAlias<$SelectionSet>]:
5152
$Select extends keyof $Node['fields']
@@ -69,14 +70,14 @@ AssertIsEqual<PickSelectsPositiveIndicatorAndNotSelectAlias<{ a: ['b', true]; b:
6970

7071
type InferSelectScalarsWildcard<
7172
$SelectionSet,
72-
$Index extends Schema.Index,
73+
$Index extends SchemaIndex,
7374
$Node extends Schema.Output.Object$2,
7475
> = {
7576
[$Key in keyof PickScalarFields<$Node>]: InferField<$SelectionSet, $Node['fields'][$Key], $Index>
7677
}
7778

7879
// todo could we use this since the valuesoremptyobject could drop the nevers?
79-
// type HandFieldExpressionAliases<$SelectionSet, $Index extends Schema.Index, $Node extends Schema.Output.Object$2> =
80+
// type HandFieldExpressionAliases<$SelectionSet, $Index extends SchemaIndex, $Node extends Schema.Output.Object$2> =
8081
// ValuesOrEmptyObject<
8182
// {
8283
// [$KeyExpression in keyof $SelectionSet & string]:
@@ -94,15 +95,15 @@ type InferSelectScalarsWildcard<
9495
// >
9596

9697
// dprint-ignore
97-
export type InferUnion<$SelectionSet, $Index extends Schema.Index, $Node extends Schema.Output.Union> =
98+
export type InferUnion<$SelectionSet, $Index extends SchemaIndex, $Node extends Schema.Output.Union> =
9899
InferInlineFragmentTypeConditional<$SelectionSet, $Node['members'][number], $Index>
99100

100101
// dprint-ignore
101-
export type InferInterface<$SelectionSet, $Index extends Schema.Index, $Node extends Schema.Output.Interface> =
102+
export type InferInterface<$SelectionSet, $Index extends SchemaIndex, $Node extends Schema.Output.Interface> =
102103
InferInlineFragmentTypeConditional<$SelectionSet, $Node['implementors'][number], $Index>
103104

104105
// dprint-ignore
105-
type InferInlineFragmentTypeConditional<$SelectionSet, $Node extends Schema.Output.Object$2, $Index extends Schema.Index> =
106+
type InferInlineFragmentTypeConditional<$SelectionSet, $Node extends Schema.Output.Object$2, $Index extends SchemaIndex> =
106107
$Node extends any // force distribution
107108
? InferObject<
108109
& GetKeyOr<

0 commit comments

Comments
 (0)