Skip to content

Commit 05a9717

Browse files
authored
feat(extension-system): request result data types (#1295)
1 parent 0e5918c commit 05a9717

File tree

22 files changed

+169
-80
lines changed

22 files changed

+169
-80
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
],
7171
"repository": {
7272
"type": "git",
73-
"url": "https://github.com/graffle-js/graffle.git"
73+
"url": "git+https://github.com/graffle-js/graffle.git"
7474
},
7575
"keywords": [
7676
"graphql",

src/client/client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { requestMethodsProperties } from '../documentBuilder/requestMethods/requestMethods.js' // todo
1+
import { requestMethodsProperties } from '../documentBuilder/requestMethods/requestMethods.js'
22
import type { Anyware } from '../lib/anyware/__.js'
33
import { proxyGet } from '../lib/prelude.js'
44
import type { TypeFunction } from '../lib/type-function/__.js'

src/client/handleOutput.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { GraphQLError } from 'graphql'
22
import type { Simplify } from 'type-fest'
3-
import type { SimplifyDeepExcept } from '../documentBuilder/Simplify.js'
43
import type { Extension } from '../entrypoints/extensionkit.js'
54
import type { Anyware } from '../lib/anyware/__.js'
65
import { Errors } from '../lib/errors/__.js'
@@ -17,6 +16,7 @@ import {
1716
import type { RequestPipelineBase } from '../requestPipeline/RequestPipeline.js'
1817
import type { Context } from '../types/context.js'
1918
import type { GlobalRegistry } from '../types/GlobalRegistry/GlobalRegistry.js'
19+
import type { RequestResult } from '../types/RequestResult.ts/__.js'
2020
import {
2121
type ErrorCategory,
2222
isOutputTraditionalGraphQLOutput,
@@ -99,7 +99,7 @@ export type HandleOutputGraffleRootField<$Context extends Context, $Data extends
9999
ExcludeNull<
100100
HandleOutput<
101101
$Context,
102-
SimplifyDeepExcept<$Context['scalars']['typesDecoded'], $Data>
102+
RequestResult.Simplify<$Context, $Data>
103103
>
104104
>,
105105
$RootFieldName
@@ -117,7 +117,7 @@ export type HandleOutput<$Context extends Context, $Data extends SomeObjectData>
117117
$Context,
118118
Envelope<
119119
$Context,
120-
SimplifyDeepExcept<$Context['scalars']['typesDecoded'], $Data>
120+
RequestResult.Simplify<$Context, $Data>
121121
>
122122
>
123123

src/client/properties/scalar.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { type Context } from '../../types/context.js'
22
import type { GlobalRegistry } from '../../types/GlobalRegistry/GlobalRegistry.js'
33
import { Schema } from '../../types/Schema/__.js'
4-
import type { GetDecoded, GetEncoded } from '../../types/Schema/nodes/Scalar/helpers.js'
54
import { type Client } from '../client.js'
65
import type { ExtensionChainableRegistry } from '../client.js'
76
import { createProperties } from '../helpers.js'
@@ -45,8 +44,8 @@ export type ScalarMethod<
4544
{
4645
[_ in keyof $Context]: _ extends 'scalars' ? {
4746
map: $Context[_]['map'] & { [_ in $Scalar['name']]: $Scalar }
48-
typesEncoded: $Context[_]['typesEncoded'] | GetEncoded<$Scalar>
49-
typesDecoded: $Context[_]['typesDecoded'] | GetDecoded<$Scalar>
47+
typesEncoded: $Context[_]['typesEncoded'] | Schema.Scalar.GetEncoded<$Scalar>
48+
typesDecoded: $Context[_]['typesDecoded'] | Schema.Scalar.GetDecoded<$Scalar>
5049
}
5150
: $Context[_]
5251
},
@@ -55,6 +54,17 @@ export type ScalarMethod<
5554
>
5655
}
5756

57+
// todo review if really needed for keeping type instance count low v
58+
// We do not use this above to reduce type instance count
59+
export type AddScalar<$Context extends Context, $Scalar extends Schema.Scalar> = {
60+
[_ in keyof $Context]: _ extends 'scalars' ? {
61+
map: $Context[_]['map'] & { [_ in $Scalar['name']]: $Scalar }
62+
typesEncoded: $Context[_]['typesEncoded'] | Schema.Scalar.GetEncoded<$Scalar>
63+
typesDecoded: $Context[_]['typesDecoded'] | Schema.Scalar.GetDecoded<$Scalar>
64+
}
65+
: $Context[_]
66+
}
67+
5868
type Arguments = [Schema.Scalar] | [string, { decode: (value: string) => any; encode: (value: any) => string }]
5969

6070
export const scalarProperties = createProperties((builder, state) => {

src/client/properties/use.ts

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ export type UseMethod<
99
out $Extension_ extends object,
1010
out $ExtensionChainable_ extends ExtensionChainableRegistry,
1111
> = <extension extends Extension>(extension: extension) => Client<
12+
// @ts-expect-error fixme
1213
UseReducer<$Context, extension>,
1314
$Extension_,
1415
// @ts-expect-error
@@ -23,7 +24,7 @@ export type UseReducer<
2324
$Context extends Context,
2425
$Extension extends Extension,
2526
> =
26-
AddTypeHooks<
27+
Extension.AddTypeHooksFromExtension<
2728
AddTransport<
2829
AddExtension<
2930
$Context,
@@ -95,15 +96,6 @@ type AddTransport<
9596
$Extension['transport']
9697
>
9798

98-
type AddTypeHooks<
99-
$Context extends Context,
100-
$Extension extends Extension,
101-
> = ConfigManager.UpdateKeyWithAppendMany<
102-
$Context,
103-
'typeHookOnRequestResult',
104-
$Extension['typeHooks']['onRequestResult']
105-
>
106-
10799
type AddExtension<
108100
$Context extends Context,
109101
$Extension extends Extension,

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@ 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'
55
import { assertEqual } from '../../lib/assert-equal.js'
6+
import type { RequestResult } from '../../types/RequestResult.ts/__.js'
67
import type { Registry } from '../../types/Schema/nodes/Scalar/helpers.js'
7-
import type { DocumentBuilder } from '../__.js'
88
import type { InferResult } from './__.js'
99

10-
type $<$SelectionSet extends SelectionSets.Query> = DocumentBuilder.SimplifyDeep<
10+
type $<$SelectionSet extends SelectionSets.Query> = RequestResult.SimplifyWithEmptyContext<
1111
InferResult.OperationQuery<$SelectionSet, Schema>
1212
>
1313

src/documentBuilder/Simplify.test-d.ts

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

src/documentBuilder/Simplify.ts

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

src/documentBuilder/_.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export * from './Simplify.js'
1+
export * from './InferResult/__.js'

src/entrypoints/utilities-for-generated.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ export type { ConfigGetOutputError, HandleOutput, HandleOutputGraffleRootField }
44
export { useReducer } from '../client/properties/use.js'
55
export { type DocumentRunner } from '../documentBuilder/requestMethods/document.js'
66
export * from '../documentBuilder/Select/__.js'
7-
export { type SimplifyDeep, type SimplifyDeepExcept } from '../documentBuilder/Simplify.js'
87
export { type AssertExtendsObject, type Exact, type ExactNonEmpty, type UnionExpanded } from '../lib/prelude.js'
98
export { TypeFunction } from '../lib/type-function/__.js'
109
export type { ClientTransports } from '../types/context.js'

0 commit comments

Comments
 (0)