Skip to content

Commit 21674a5

Browse files
authored
improve(document-builder): deeply simplify results (#1268)
1 parent 8bf1621 commit 21674a5

File tree

21 files changed

+317
-247
lines changed

21 files changed

+317
-247
lines changed

src/client/builderExtensions/scalar.test-d.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,11 @@ Graffle.create({ schema: `foo`, schemaMap }).scalar(`Foo`, _)
1616
// @ts-expect-error "Foo" is not a scalar name in the schema.
1717
Graffle.create({ schema: `foo`, schemaMap }).scalar(FooScalar)
1818
Graffle.create({ schema: `foo`, schemaMap }).scalar(`Date`, _)
19-
Graffle.create({ schema: `foo`, schemaMap }).scalar(DateScalar)
2019
Graffle.create({ schema: `foo`, schemaMap }).scalar(`Int`, _)
20+
{
21+
const graffle = Graffle.create({ schema: `foo`, schemaMap }).scalar(DateScalar)
22+
assertEqual<
23+
typeof graffle._.scalars,
24+
{ typesDecoded: Date; typesEncoded: string; map: { Date: typeof DateScalar } }
25+
>()
26+
}

src/client/builderExtensions/scalar.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,10 @@ type ScalarMethod<$Args extends Builder.Extension.Parameters<BuilderExtensionSca
4040
$Args['context'],
4141
['scalars'],
4242
Simplify<
43-
Schema.Scalar.Registry.AddScalar<$Args['context']['scalars'], Schema.Scalar<$Name, $Decoded, string>>
43+
Schema.Scalar.Registry.AddScalar<
44+
$Args['context']['scalars'],
45+
Schema.Scalar<$Name, $Decoded, string>
46+
>
4447
>
4548
>
4649
>

src/documentBuilder/InferResult/OutputField.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import type { SimplifyNullable } from '../../lib/prelude.js'
21
import type { TSErrorDescriptive } from '../../lib/ts-error.js'
32
import type { Schema } from '../../types/Schema/__.js'
43
import type { InlineType } from '../../types/SchemaDrivenDataMap/InlineType.js'
@@ -15,12 +14,12 @@ export type OutputField<$SelectionSet, $Field extends Schema.OutputField, $Schem
1514
: (
1615
| FieldDirectiveInclude<$SelectionSet>
1716
| FieldDirectiveSkip<$SelectionSet>
18-
| SimplifyNullable<
17+
| //SimplifyNullable<
1918
InlineType.Infer<
2019
$Field['inlineType'],
2120
FieldType<$Schema, Omit<$SelectionSet, '$'>, $Field['namedType']>
2221
>
23-
>
22+
//>
2423
)
2524

2625
// dprint-ignore

src/documentBuilder/InferResult/OutputObject.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import type { IsNever, Simplify } from 'type-fest'
1+
import type { IsNever } from 'type-fest'
22
import { assertEqual } from '../../lib/assert-equal.js'
3-
import type { AssertExtendsObject, GetOrNever, SimplifyExcept, StringKeyof } from '../../lib/prelude.js'
3+
import type { AssertExtendsObject, GetOrNever, StringKeyof } from '../../lib/prelude.js'
44
import type { TSErrorDescriptive } from '../../lib/ts-error.js'
55
import type { Schema } from '../../types/Schema/__.js'
66
import type { Select } from '../Select/__.js'
@@ -15,27 +15,27 @@ export type OutputObject<
1515
$Schema extends Schema,
1616
$Node extends Schema.OutputObject
1717
> =
18-
SimplifyExcept<
19-
$Schema['scalars']['typesDecoded'],
18+
// SimplifyExcept<
19+
// $Schema['scalars']['typesDecoded'],
2020
& OutputObject_<$SelectionSet, $Schema, $Node>
2121
& InlineFragmentKeys<$SelectionSet, $Schema, $Node>
22-
>
22+
// >
2323

2424
// dprint-ignore
2525
type OutputObject_<
2626
$SelectionSet extends object,
2727
$Schema extends Schema,
2828
$Node extends Schema.OutputObject,
2929
> =
30-
Simplify<
30+
// Simplify<
3131
Select.SelectScalarsWildcard.IsSelectScalarsWildcard<$SelectionSet> extends true
3232
// todo this needs to be an extension and/or only available when sddm is present
3333
// todo what about when scalars wildcard is combined with other fields like relations?
3434
? ScalarsWildcard<$SelectionSet, $Schema, $Node>
3535
:
3636
& NonAliasKeys<$SelectionSet, $Schema, $Node>
3737
& Alias<$Schema, $Node, $SelectionSet>
38-
>
38+
// >
3939

4040
// dprint-ignore
4141
type NonAliasKeys<$SelectionSet, $Schema extends Schema, $Node extends Schema.OutputObject> = {

src/documentBuilder/InferResult/__.test-d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import type { Simplify } from 'type-fest'
21
import type { DateScalar } from '../../../tests/_/fixtures/scalars.js'
32
import type { db } from '../../../tests/_/schemas/db.js'
43
import type { Schema } from '../../../tests/_/schemas/kitchen-sink/graffle/modules/schema.js'
54
import type * as SelectionSets from '../../../tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.js'
65
import { assertEqual } from '../../lib/assert-equal.js'
6+
import type { SimplifyDeep } from '../../lib/prelude.js'
77
import type { Registry } from '../../types/Schema/nodes/Scalar/helpers.js'
88
import type { InferResult } from './__.js'
99

10-
type $<$SelectionSet extends SelectionSets.Query> = Simplify<InferResult.OperationQuery<$SelectionSet, Schema>>
10+
type $<$SelectionSet extends SelectionSets.Query> = SimplifyDeep<InferResult.OperationQuery<$SelectionSet, Schema>>
1111

1212
type $Registry = Registry.AddScalar<Registry.Empty, typeof DateScalar>
1313

src/documentBuilder/requestMethods/document.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
import type { Simplify, UnionToTuple } from 'type-fest'
1+
import type { UnionToTuple } from 'type-fest'
22
import type { Context } from '../../client/context.js'
33
import { type HandleOutput } from '../../client/handleOutput.js'
44
import type { InferResult } from '../../documentBuilder/InferResult/__.js'
55
import type { Select } from '../../documentBuilder/Select/__.js'
66
import type { Schema } from '../../entrypoints/schema.js'
7-
import type { IsTupleMultiple } from '../../lib/prelude.js'
7+
import type { IsTupleMultiple, SimplifyDeepExcept } from '../../lib/prelude.js'
88

99
// dprint-ignore
1010
export type DocumentRunner<
@@ -18,7 +18,8 @@ export type DocumentRunner<
1818
const $Name extends string = $Params extends [] ? $$Name : $Params[0],
1919
>(...params: $Params) =>
2020
Promise<
21-
Simplify<
21+
SimplifyDeepExcept<
22+
$$Context['scalars']['typesDecoded'],
2223
HandleOutput<
2324
$$Context,
2425
InferResult.Operation<

src/documentBuilder/requestMethods/requestMethods.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import * as Schema from '../../../tests/_/schemas/kitchen-sink/schema.js'
77
// import { Graffle as Pokemon } from '../../../tests/_/schemas/pokemon/graffle/__.js'
88

99
const graffle = Graffle.create({ schema: Schema.schema }).scalar(DateScalar)
10+
graffle._.scalars.typesDecoded
1011

1112
// dprint-ignore
1213
test(`query`, async () => {
@@ -21,7 +22,6 @@ test(`query`, async () => {
2122
expectTypeOf<Parameters<typeof graffle.query.stringWithRequiredArg>>().toEqualTypeOf<[input: Graffle.SelectionSets.Query.stringWithRequiredArg]>()
2223
// scalar custom
2324
expectTypeOf(await graffle.query.date()).toMatchTypeOf<Date | null>()
24-
2525
// scalar with explicit indicators
2626
// positive indicator
2727
expectTypeOf(await graffle.query.idNonNull(true)).toEqualTypeOf<string>()

src/entrypoints/utilities-for-generated.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ export {
88
type AssertExtendsObject,
99
type Exact,
1010
type ExactNonEmpty,
11+
type SimplifyDeep,
12+
type SimplifyDeepExcept,
1113
type SimplifyExcept,
1214
type UnionExpanded,
1315
} from '../lib/prelude.js'

0 commit comments

Comments
 (0)