Skip to content

Commit 76c8994

Browse files
authored
improve(document-builder): no simplify custom scalars (#1232)
1 parent 0f10bad commit 76c8994

File tree

22 files changed

+474
-249
lines changed

22 files changed

+474
-249
lines changed

src/documentBuilder/InferResult/OutputObject.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import type { ConditionalSimplify } from 'type-fest/source/conditional-simplify.js'
2-
import type { StringKeyof } from '../../lib/prelude.js'
1+
import type { SimplifyExcept, StringKeyof } from '../../lib/prelude.js'
32
import type { TSErrorDescriptive } from '../../lib/ts-error.js'
43
import type { Schema } from '../../types/Schema/__.js'
54
import type { Select } from '../Select/__.js'
@@ -11,10 +10,10 @@ export type OutputObject<$SelectionSet, $Schema extends Schema, $Node extends Sc
1110
Select.SelectScalarsWildcard.IsSelectScalarsWildcard<$SelectionSet> extends true
1211
// todo what about when scalars wildcard is combined with other fields like relations?
1312
? ScalarsWildcard<$SelectionSet, $Schema, $Node>
14-
: ConditionalSimplify<
13+
: SimplifyExcept<
14+
$Schema['scalars']['typesDecoded'],
1515
& SelectionNonSelectAlias<$SelectionSet, $Schema, $Node>
16-
& Alias<$Schema, $Node, $SelectionSet>,
17-
$Schema['scalars']['typesDecoded']
16+
& Alias<$Schema, $Node, $SelectionSet>
1817
>
1918

2019
type SelectionNonSelectAlias<$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,4 +1,4 @@
1-
import type { Date } from '../../../tests/_/fixtures/scalars.js'
1+
import type { DateScalar } from '../../../tests/_/fixtures/scalars.js'
22
import type { db } from '../../../tests/_/schemas/db.js'
33
import type { Schema } from '../../../tests/_/schemas/kitchen-sink/graffle/modules/schema.js'
44
import type * as SelectionSets from '../../../tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.js'
@@ -9,7 +9,7 @@ import type { PickSelectsPositiveIndicatorAndNotSelectAlias } from './OutputObje
99

1010
type $<$SelectionSet extends SelectionSets.Query> = InferResult.OperationQuery<$SelectionSet, Schema>
1111

12-
type $Registry = Registry.AddScalar<Registry.Empty, typeof Date>
12+
type $Registry = Registry.AddScalar<Registry.Empty, typeof DateScalar>
1313

1414
type $WithDate<$SelectionSet extends SelectionSets.Query<$Registry>> = InferResult.OperationQuery<
1515
$SelectionSet,

src/documentBuilder/SelectGraphQLMapper/toGraphQL.test.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect, test } from 'vitest'
2-
import { Date } from '../../../tests/_/fixtures/scalars.js'
2+
import { DateScalar } from '../../../tests/_/fixtures/scalars.js'
33
import { db } from '../../../tests/_/schemas/db.js'
44
import { schemaDrivenDataMap } from '../../../tests/_/schemas/kitchen-sink/graffle/modules/schema-driven-data-map.js'
55
import type * as SelectionSets from '../../../tests/_/schemas/kitchen-sink/graffle/modules/selection-sets.js'
@@ -15,7 +15,9 @@ type CasesDescriptiveQuery = [
1515
]
1616
const testEachQueryWithDescription = test.for.bind(test)<CasesDescriptiveQuery>
1717

18-
type QueryWithDate = SelectionSets.Query<Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof Date>>
18+
type QueryWithDate = SelectionSets.Query<
19+
Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof DateScalar>
20+
>
1921

2022
type CasesDescriptiveQueryWithCustomScalars = [
2123
description: string,
@@ -142,5 +144,5 @@ const customScalarWithCodecCases = testEachQueryWithDescriptionWithCustomScalars
142144
[`args - custom scalar - input object field` , { dateArgInputObject: { $: { input: { idRequired: ``, dateRequired: db.date0, date: db.date1 } } } }],
143145
[`args - custom scalar - nested input object field` , { InputObjectNested: { $: { input: { InputObject: { idRequired: ``, dateRequired: db.date0, date: db.date1 } } } } }],
144146
])
145-
customScalarWithCodecCases(...tester({ variables: true, scalars: { Date } }))
146-
customScalarWithCodecCases(...tester({ variables: false, scalars: { Date } }))
147+
customScalarWithCodecCases(...tester({ variables: true, scalars: { Date: DateScalar } }))
148+
customScalarWithCodecCases(...tester({ variables: false, scalars: { Date: DateScalar } }))

src/entrypoints/utilities-for-generated.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ export type {
88
} from '../layers/6_client/handleOutput.js'
99
export { type DocumentRunner } from '../layers/6_client/requestMethods/document.js'
1010
export type { Config } from '../layers/6_client/Settings/Config.js'
11-
export { type Exact, type ExactNonEmpty, type UnionExpanded } from '../lib/prelude.js'
11+
export { type Exact, type ExactNonEmpty, type SimplifyExcept, type UnionExpanded } from '../lib/prelude.js'
1212
export { TypeFunction } from '../lib/type-function/__.js'
1313
export { type GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
1414
export { Schema } from '../types/Schema/__.js'

src/extensions/CustomScalars/decode.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { describe, expect } from 'vitest'
2-
import { Date } from '../../../tests/_/fixtures/scalars.js'
2+
import { DateScalar } from '../../../tests/_/fixtures/scalars.js'
33
import { createResponse, test } from '../../../tests/_/helpers.js'
44
import { db } from '../../../tests/_/schemas/db.js'
55
import type { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
@@ -9,7 +9,7 @@ import { Grafaid } from '../../lib/grafaid/__.js'
99
import type { Schema } from '../../types/Schema/__.js'
1010

1111
type QueryWithDate = Graffle.SelectionSets.Query<
12-
Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof Date>
12+
Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof DateScalar>
1313
>
1414

1515
type TestCase = [
@@ -26,7 +26,7 @@ const withBatch: TestCaseWith = [
2626
{},
2727
async ([_, query, responseData, expectedData], { fetch, kitchenSinkHttp: kitchenSink }) => {
2828
fetch.mockResolvedValueOnce(createResponse({ data: responseData }))
29-
expect(await kitchenSink.scalar(Date).query.$batch(query)).toEqual(expectedData)
29+
expect(await kitchenSink.scalar(DateScalar).query.$batch(query)).toEqual(expectedData)
3030
},
3131
]
3232

@@ -38,7 +38,7 @@ const withGqlDocument: TestCaseWith = [
3838
const { document } = SelectionSetGraphqlMapper.toGraphQL(
3939
Select.Document.createDocumentNormalizedFromQuerySelection(query as any),
4040
)
41-
expect(await kitchenSink.scalar(Date).gql(document).send()).toEqual(expectedData)
41+
expect(await kitchenSink.scalar(DateScalar).gql(document).send()).toEqual(expectedData)
4242
},
4343
]
4444

@@ -50,7 +50,7 @@ const withGqlString: TestCaseWith = [
5050
const { document } = SelectionSetGraphqlMapper.toGraphQL(
5151
Select.Document.normalizeOrThrow({ query: { foo: query as any } }),
5252
)
53-
expect(await kitchenSink.scalar(Date).gql(Grafaid.Document.print(document)).send()).toEqual(expectedData)
53+
expect(await kitchenSink.scalar(DateScalar).gql(Grafaid.Document.print(document)).send()).toEqual(expectedData)
5454
},
5555
]
5656

@@ -107,7 +107,7 @@ describe(`$batch`, () => {
107107
describe(`object field in union`, () => {
108108
testUnionCases(`%s`, async ([_, query, responseData, expectedData], { fetch, kitchenSinkHttp: kitchenSink }) => {
109109
fetch.mockResolvedValueOnce(createResponse({ data: responseData }))
110-
expect(await kitchenSink.scalar(Date).query.$batch(query)).toEqual(expectedData)
110+
expect(await kitchenSink.scalar(DateScalar).query.$batch(query)).toEqual(expectedData)
111111
})
112112
})
113113
})

src/extensions/CustomScalars/encode.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { expect } from 'vitest'
2-
import { Date } from '../../../tests/_/fixtures/scalars.js'
2+
import { DateScalar } from '../../../tests/_/fixtures/scalars.js'
33
import { test } from '../../../tests/_/helpers.js'
44
import { db } from '../../../tests/_/schemas/db.js'
55
import type { Graffle } from '../../../tests/_/schemas/kitchen-sink/graffle/__.js'
@@ -11,7 +11,7 @@ import { Grafaid } from '../../lib/grafaid/__.js'
1111
import type { Schema } from '../../types/Schema/__.js'
1212

1313
type QueryWithDate = Graffle.SelectionSets.Query<
14-
Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof Date>
14+
Schema.Scalar.Registry.AddScalar<Schema.Scalar.Registry.Empty, typeof DateScalar>
1515
>
1616

1717
type TestCase = [
@@ -36,7 +36,7 @@ const testCases = test.for<TestCase>([
3636
])
3737

3838
testCases(`%s`, async ([_, query, expectedVariables], { kitchenSink }) => {
39-
const g = kitchenSink.use(Spy()).scalar(Date)
39+
const g = kitchenSink.use(Spy()).scalar(DateScalar)
4040
const { document, operationsVariables } = SelectionSetGraphqlMapper.toGraphQL(
4141
Select.Document.createDocumentNormalizedFromQuerySelection(query as any),
4242
{

0 commit comments

Comments
 (0)