@model-ts/graphql 0.0.0-stage → 7.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (114) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1280 -2
  3. package/dist/.tsbuildinfo +1 -0
  4. package/dist/Assembly.d.ts +24 -0
  5. package/dist/Assembly.d.ts.map +1 -0
  6. package/dist/Assembly.js +236 -0
  7. package/dist/Assembly.js.map +1 -0
  8. package/dist/Builder.d.ts +27 -0
  9. package/dist/Builder.d.ts.map +1 -0
  10. package/dist/Builder.js +40 -0
  11. package/dist/Builder.js.map +1 -0
  12. package/dist/Connections.d.ts +41 -0
  13. package/dist/Connections.d.ts.map +1 -0
  14. package/dist/Connections.js +243 -0
  15. package/dist/Connections.js.map +1 -0
  16. package/dist/Definitions.d.ts +139 -0
  17. package/dist/Definitions.d.ts.map +1 -0
  18. package/dist/Definitions.js +117 -0
  19. package/dist/Definitions.js.map +1 -0
  20. package/dist/Errors.d.ts +39 -0
  21. package/dist/Errors.d.ts.map +1 -0
  22. package/dist/Errors.js +103 -0
  23. package/dist/Errors.js.map +1 -0
  24. package/dist/Execution.d.ts +52 -0
  25. package/dist/Execution.d.ts.map +1 -0
  26. package/dist/Execution.js +174 -0
  27. package/dist/Execution.js.map +1 -0
  28. package/dist/FieldRuntime.d.ts +5 -0
  29. package/dist/FieldRuntime.d.ts.map +1 -0
  30. package/dist/FieldRuntime.js +27 -0
  31. package/dist/FieldRuntime.js.map +1 -0
  32. package/dist/FieldTypes.d.ts +232 -0
  33. package/dist/FieldTypes.d.ts.map +1 -0
  34. package/dist/FieldTypes.js +6 -0
  35. package/dist/FieldTypes.js.map +1 -0
  36. package/dist/Fields.d.ts +8 -0
  37. package/dist/Fields.d.ts.map +1 -0
  38. package/dist/Fields.js +72 -0
  39. package/dist/Fields.js.map +1 -0
  40. package/dist/Formatting.d.ts +25 -0
  41. package/dist/Formatting.d.ts.map +1 -0
  42. package/dist/Formatting.js +29 -0
  43. package/dist/Formatting.js.map +1 -0
  44. package/dist/GraphQL.d.ts +10 -0
  45. package/dist/GraphQL.d.ts.map +1 -0
  46. package/dist/GraphQL.js +5 -0
  47. package/dist/GraphQL.js.map +1 -0
  48. package/dist/InputTypes.d.ts +27 -0
  49. package/dist/InputTypes.d.ts.map +1 -0
  50. package/dist/InputTypes.js +203 -0
  51. package/dist/InputTypes.js.map +1 -0
  52. package/dist/Registry.d.ts +70 -0
  53. package/dist/Registry.d.ts.map +1 -0
  54. package/dist/Registry.js +3 -0
  55. package/dist/Registry.js.map +1 -0
  56. package/dist/Resolver.d.ts +30 -0
  57. package/dist/Resolver.d.ts.map +1 -0
  58. package/dist/Resolver.js +76 -0
  59. package/dist/Resolver.js.map +1 -0
  60. package/dist/Results.d.ts +20 -0
  61. package/dist/Results.d.ts.map +1 -0
  62. package/dist/Results.js +79 -0
  63. package/dist/Results.js.map +1 -0
  64. package/dist/ScalarBoundary.d.ts +9 -0
  65. package/dist/ScalarBoundary.d.ts.map +1 -0
  66. package/dist/ScalarBoundary.js +31 -0
  67. package/dist/ScalarBoundary.js.map +1 -0
  68. package/dist/Scalars.d.ts +9 -0
  69. package/dist/Scalars.d.ts.map +1 -0
  70. package/dist/Scalars.js +104 -0
  71. package/dist/Scalars.js.map +1 -0
  72. package/dist/SchemaTypes.d.ts +55 -0
  73. package/dist/SchemaTypes.d.ts.map +1 -0
  74. package/dist/SchemaTypes.js +47 -0
  75. package/dist/SchemaTypes.js.map +1 -0
  76. package/dist/Subscription.d.ts +6 -0
  77. package/dist/Subscription.d.ts.map +1 -0
  78. package/dist/Subscription.js +60 -0
  79. package/dist/Subscription.js.map +1 -0
  80. package/dist/Testing.d.ts +52 -0
  81. package/dist/Testing.d.ts.map +1 -0
  82. package/dist/Testing.js +74 -0
  83. package/dist/Testing.js.map +1 -0
  84. package/dist/index.d.ts +2 -0
  85. package/dist/index.d.ts.map +1 -0
  86. package/dist/index.js +2 -0
  87. package/dist/index.js.map +1 -0
  88. package/dist/internal/SubscriptionRule.d.ts +8 -0
  89. package/dist/internal/SubscriptionRule.d.ts.map +1 -0
  90. package/dist/internal/SubscriptionRule.js +73 -0
  91. package/dist/internal/SubscriptionRule.js.map +1 -0
  92. package/package.json +55 -4
  93. package/src/Assembly.ts +352 -0
  94. package/src/Builder.ts +110 -0
  95. package/src/Connections.ts +374 -0
  96. package/src/Definitions.ts +465 -0
  97. package/src/Errors.ts +188 -0
  98. package/src/Execution.ts +354 -0
  99. package/src/FieldRuntime.ts +32 -0
  100. package/src/FieldTypes.ts +667 -0
  101. package/src/Fields.ts +117 -0
  102. package/src/Formatting.ts +54 -0
  103. package/src/GraphQL.ts +50 -0
  104. package/src/InputTypes.ts +266 -0
  105. package/src/Registry.ts +157 -0
  106. package/src/Resolver.ts +176 -0
  107. package/src/Results.ts +128 -0
  108. package/src/ScalarBoundary.ts +30 -0
  109. package/src/Scalars.ts +143 -0
  110. package/src/SchemaTypes.ts +90 -0
  111. package/src/Subscription.ts +93 -0
  112. package/src/Testing.ts +144 -0
  113. package/src/index.ts +1 -0
  114. package/src/internal/SubscriptionRule.ts +90 -0
@@ -0,0 +1,667 @@
1
+ import type { Effect, Option, Schema, Stream } from "effect"
2
+ import { type GraphQLFieldConfig, type GraphQLOutputType } from "graphql"
3
+ import { type Connection, type ConnectionArgs } from "./Connections.ts"
4
+ import type { RootDefinition } from "./Definitions.ts"
5
+ import type { InputTypes } from "./InputTypes.ts"
6
+ import {
7
+ type Scalars,
8
+ type NamesOfKind,
9
+ type ModelAt,
10
+ type Values,
11
+ } from "./Registry.ts"
12
+ import {
13
+ type ErrorSchema,
14
+ type ErrorsOf,
15
+ type ResultOptions,
16
+ } from "./Results.ts"
17
+
18
+ export type Resolved<A, E, R> = A | Effect.Effect<A, E, R>
19
+
20
+ export type RuntimeRef =
21
+ | string
22
+ | { readonly kind: "list" | "nullable"; readonly of: RuntimeRef }
23
+
24
+ export declare const outputValue: unique symbol
25
+
26
+ /** Preserve a nullable ref's named success type for result-union validation. */
27
+ export declare const outputResult: unique symbol
28
+
29
+ export interface OutputRef<A, Result = unknown> {
30
+ readonly [outputResult]: Result
31
+ readonly kind: "list" | "nullable"
32
+ readonly of: RuntimeRef
33
+ readonly [outputValue]: A
34
+ }
35
+
36
+ /** A config-less connection helper retains the node for the connection overloads. */
37
+ export interface ConnectionRef<N extends string> {
38
+ readonly kind: "connection"
39
+ readonly node: N
40
+ }
41
+
42
+ export type RootKind = "query" | "mutation" | "subscription"
43
+
44
+ /** Root helpers add a name and return a definition; the field config stays shared. */
45
+ type FieldArguments<K, N extends string, T, I> = [
46
+ ...name: K extends RootKind ? [name: N] : [],
47
+ type: T,
48
+ input: I,
49
+ ]
50
+
51
+ type FieldSource<K, S> = K extends RootKind ? unknown : S
52
+
53
+ type FieldResult<
54
+ K,
55
+ N extends string,
56
+ S,
57
+ R,
58
+ C,
59
+ Subscription extends boolean = false,
60
+ > = K extends RootKind
61
+ ? RootDefinition<
62
+ K,
63
+ { readonly [P in N]: SourceField<unknown, R, C, Subscription> },
64
+ C
65
+ >
66
+ : SourceField<S, R, C, Subscription>
67
+
68
+ type ResultTarget<T> = T extends OutputRef<unknown, infer Result> ? Result : T
69
+
70
+ export type ConnectionNode<Types> = NamesOfKind<
71
+ Types,
72
+ "object" | "interface" | "union"
73
+ >
74
+
75
+ export type ObjectName<Types> = NamesOfKind<Types, "object">
76
+
77
+ export type ResultName<Types> =
78
+ | ObjectName<Types>
79
+ | NamesOfKind<Types, "union">
80
+ | `${ObjectName<Types>}Edge`
81
+ | `${ObjectName<Types>}Connection`
82
+ | "PageInfo"
83
+
84
+ export type Ref<Types> =
85
+ | Extract<keyof Values<Types>, string>
86
+ | keyof Scalars
87
+ | OutputRef<unknown, unknown>
88
+
89
+ export type Value<Types, T> =
90
+ T extends OutputRef<infer A, unknown>
91
+ ? A
92
+ : T extends keyof Values<Types>
93
+ ? Values<Types>[T]
94
+ : T extends keyof Scalars
95
+ ? Scalars[T]
96
+ : never
97
+
98
+ export type ListOf<Types, T> = ReadonlyArray<Value<Types, T>>
99
+
100
+ export type NullableOf<Types, T> =
101
+ | Value<Types, T>
102
+ | null
103
+ | undefined
104
+ | Option.Option<Value<Types, T>>
105
+
106
+ export type ArgFields = Readonly<
107
+ Record<string, Schema.ConstraintDecoder<unknown, never>>
108
+ >
109
+
110
+ export type ArgsOf<Args extends ArgFields> = Schema.Struct<Args>["Type"]
111
+
112
+ export interface Description {
113
+ readonly description?: string
114
+ readonly deprecationReason?: string
115
+ }
116
+
117
+ /** Resolvers, authorize, totalCount and nodes all receive the request context as the third argument. */
118
+
119
+ export type Resolve<S, Args, A, E, R, C> = (
120
+ source: S,
121
+ args: Args,
122
+ context: C,
123
+ ) => Resolved<A, E, R>
124
+
125
+ export interface FieldConfig<
126
+ S,
127
+ Args extends ArgFields,
128
+ A,
129
+ E,
130
+ R,
131
+ AR,
132
+ C,
133
+ > extends Description {
134
+ readonly args?: Args
135
+ readonly subscribe?: never
136
+ readonly resolve: Resolve<S, ArgsOf<NoInfer<Args>>, A, E, R, C>
137
+ readonly authorize?: Resolve<S, ArgsOf<NoInfer<Args>>, boolean, E, AR, C>
138
+ }
139
+
140
+ /** Subscription setup returns a stream; authorization receives each delivered value. */
141
+ export interface SubscriptionConfig<
142
+ S,
143
+ Args extends ArgFields,
144
+ A,
145
+ G,
146
+ R,
147
+ AR,
148
+ C,
149
+ > extends Description {
150
+ readonly args?: Args
151
+ readonly subscribe: (
152
+ source: S,
153
+ args: ArgsOf<NoInfer<Args>>,
154
+ context: C,
155
+ ) => Stream.Stream<A, NoInfer<G>, R>
156
+ readonly authorize?: Resolve<
157
+ A,
158
+ ArgsOf<NoInfer<Args>>,
159
+ boolean,
160
+ NoInfer<G>,
161
+ AR,
162
+ C
163
+ >
164
+ readonly resolve?: never
165
+ }
166
+
167
+ export interface UnionFieldConfig<
168
+ S,
169
+ Args extends ArgFields,
170
+ A,
171
+ E extends readonly ErrorSchema[],
172
+ R,
173
+ G,
174
+ AR,
175
+ C,
176
+ > extends FieldConfig<S, Args, A, ErrorsOf<NoInfer<E>> | G, R, AR, C> {
177
+ /** Typed errors returned as members of the generated "<Field>Result" union. */
178
+ readonly errors?: E
179
+ readonly result?: ResultOptions
180
+ }
181
+ /** A resolver, or a config with args, errors or a description. */
182
+
183
+ export type FieldInput<S, A, R, G, Args extends ArgFields, AR, C> =
184
+ | Resolve<S, {}, A, NoInfer<G>, R, C>
185
+ | FieldConfig<S, Args, A, NoInfer<G>, R, AR, C>
186
+
187
+ export type UnionRule<Types, T, E> = E extends readonly []
188
+ ? unknown
189
+ : ResultTarget<T> extends ResultName<Types>
190
+ ? unknown
191
+ : {
192
+ readonly errors: "Result unions need an object type or object union; use a registered object or union"
193
+ }
194
+
195
+ export type ResultRule<Types, T> =
196
+ ResultTarget<T> extends ResultName<Types>
197
+ ? unknown
198
+ : {
199
+ readonly result?: "Result unions need an object type or object union; use a registered object or union"
200
+ }
201
+
202
+ export type ConnectionArgCheck<Args> = {
203
+ readonly [K in keyof Args]: K extends keyof ConnectionArgs
204
+ ? "Reserved pagination argument; remove it from args and use the built-in connection arguments"
205
+ : unknown
206
+ }
207
+
208
+ export interface PagedConnection<
209
+ S,
210
+ A,
211
+ Args extends ArgFields,
212
+ R,
213
+ G,
214
+ AR,
215
+ CR,
216
+ C,
217
+ > extends Description {
218
+ readonly subscribe?: never
219
+ readonly authorize?: Resolve<S, ArgsOf<NoInfer<Args>>, boolean, G, AR, C>
220
+ readonly totalCount?: Resolve<S, ArgsOf<NoInfer<Args>>, number, G, CR, C>
221
+ /** Overrides the default "<Node>Connection" name. */
222
+ readonly name?: string
223
+ readonly edgeName?: string
224
+ readonly args?: Args & ConnectionArgCheck<Args>
225
+ /** Returns one page, e.g. a model-ts paginate() result. */
226
+ readonly resolve: Resolve<
227
+ S,
228
+ ConnectionArgs & ArgsOf<NoInfer<Args>>,
229
+ Connection<A>,
230
+ G,
231
+ R,
232
+ C
233
+ >
234
+ readonly nodes?: never
235
+ }
236
+
237
+ export interface NodesConnection<
238
+ S,
239
+ A,
240
+ Args extends ArgFields,
241
+ R,
242
+ G,
243
+ AR,
244
+ CR,
245
+ C,
246
+ > extends Description {
247
+ readonly subscribe?: never
248
+ readonly authorize?: Resolve<S, ArgsOf<NoInfer<Args>>, boolean, G, AR, C>
249
+ readonly totalCount?: Resolve<S, ArgsOf<NoInfer<Args>>, number, G, CR, C>
250
+ readonly name?: string
251
+ readonly edgeName?: string
252
+ readonly args?: Args & ConnectionArgCheck<Args>
253
+ /** Returns every node; the builder slices the page and issues offset cursors. */
254
+ readonly nodes: Resolve<S, ArgsOf<NoInfer<Args>>, ReadonlyArray<A>, G, R, C>
255
+ readonly resolve?: never
256
+ }
257
+
258
+ export interface BuildContext {
259
+ readonly input: InputTypes
260
+ readonly output: (ref: RuntimeRef, coordinate: string) => GraphQLOutputType
261
+ readonly result: (
262
+ ref: string,
263
+ errors: readonly ErrorSchema[],
264
+ field: string,
265
+ options?: ResultOptions,
266
+ nullable?: boolean,
267
+ ) => GraphQLOutputType
268
+ readonly connection: (
269
+ node: string,
270
+ name: string | undefined,
271
+ coordinate: string,
272
+ counted: boolean,
273
+ edgeName?: string,
274
+ ) => GraphQLOutputType
275
+ }
276
+
277
+ export interface RequestContext {
278
+ /** The caller's request context, passed to every resolver. */
279
+ readonly context: unknown
280
+ readonly stream: (
281
+ stream: Stream.Stream<unknown, never, unknown>,
282
+ ) => AsyncIterable<unknown>
283
+ readonly run: (
284
+ effect: Effect.Effect<unknown, never, unknown>,
285
+ ) => Promise<unknown>
286
+ }
287
+
288
+ export const fieldRequirements: unique symbol = Symbol(
289
+ "GraphQL field requirements",
290
+ )
291
+
292
+ export interface Field<out R, C = {}> extends Contextual<C> {
293
+ readonly kind: "field" | "list" | "nullable" | "connection"
294
+ readonly build: (
295
+ context: BuildContext,
296
+ name: string,
297
+ coordinate?: string,
298
+ ) => GraphQLFieldConfig<unknown, RequestContext>
299
+ readonly [fieldRequirements]: R | undefined
300
+ }
301
+
302
+ export declare const fieldSource: unique symbol
303
+
304
+ export interface SourceSlot<S> {
305
+ readonly [fieldSource]: (source: S) => void
306
+ }
307
+
308
+ export type SourceField<
309
+ S,
310
+ R,
311
+ C = {},
312
+ Subscription extends boolean = false,
313
+ > = SourceSlot<S> & NoInfer<Field<R, C> & SubscriptionMarker<Subscription>>
314
+
315
+ export type SubscriptionMarker<Subscription extends boolean> =
316
+ Subscription extends true
317
+ ? { readonly "~subscription": true }
318
+ : { readonly "~subscription"?: false }
319
+
320
+ export type FieldMap<
321
+ S = never,
322
+ C = {},
323
+ Subscription extends boolean = false,
324
+ > = Readonly<Record<string, SourceField<S, unknown, C, Subscription>>>
325
+
326
+ export declare const defaultRef: unique symbol
327
+ /** Phantom declaration used by both local and root default-source checks. */
328
+
329
+ export interface DefaultField<R, T, C = {}> extends Field<R, C> {
330
+ readonly "~subscription"?: false
331
+ readonly [defaultRef]: T
332
+ }
333
+
334
+ export type SourceDefault<S, R, T, C = {}> = SourceSlot<S> &
335
+ NoInfer<DefaultField<R, T, C>>
336
+
337
+ export interface DefaultOptions<S, G, AR, C> extends Description {
338
+ readonly subscribe?: never
339
+ readonly authorize?: Resolve<S, {}, boolean, G, AR, C>
340
+ readonly resolve?: never
341
+ readonly args?: never
342
+ readonly errors?: never
343
+ }
344
+
345
+ export type ScalarHelpers<Types, G, C, Nullable extends boolean = false> = {
346
+ readonly [K in keyof ScalarMethods]: <S, AR = never>(
347
+ options?: DefaultOptions<S, G, AR, C>,
348
+ ) => SourceDefault<
349
+ S,
350
+ AR,
351
+ Nullable extends true
352
+ ? OutputRef<
353
+ | Value<Types, ScalarMethods[K]>
354
+ | null
355
+ | undefined
356
+ | Option.Option<Value<Types, ScalarMethods[K]>>
357
+ >
358
+ : ScalarMethods[K],
359
+ C
360
+ >
361
+ }
362
+
363
+ export interface ScalarMethods {
364
+ id: "ID"
365
+ string: "String"
366
+ int: "Int"
367
+ float: "Float"
368
+ boolean: "Boolean"
369
+ dateTime: "DateTime"
370
+ json: "JSON"
371
+ }
372
+
373
+ /** Keep resolver overloads last so invalid results report their expected value type. */
374
+ export interface NullableFields<Types, G, C> extends ScalarHelpers<
375
+ Types,
376
+ G,
377
+ C,
378
+ true
379
+ > {
380
+ <const T extends Ref<Types>>(
381
+ of: T,
382
+ ): OutputRef<NullableOf<Types, T>, T> &
383
+ SourceDefault<unknown, never, OutputRef<NullableOf<Types, T>, T>, C>
384
+ <S, const T extends Ref<Types>, AR = never>(
385
+ of: T,
386
+ options: DefaultOptions<S, G, AR, C>,
387
+ ): SourceDefault<S, AR, OutputRef<NullableOf<Types, T>, T>, C>
388
+ <
389
+ S,
390
+ const T extends Ref<Types>,
391
+ R = never,
392
+ const E extends readonly ErrorSchema[] = readonly [],
393
+ const Args extends ArgFields = {},
394
+ AR = never,
395
+ >(
396
+ of: T,
397
+ input:
398
+ | Resolve<S, {}, NullableOf<Types, NoInfer<T>>, NoInfer<G>, R, C>
399
+ | (UnionFieldConfig<
400
+ S,
401
+ Args,
402
+ NullableOf<Types, NoInfer<T>>,
403
+ E,
404
+ R,
405
+ NoInfer<G>,
406
+ AR,
407
+ C
408
+ > &
409
+ UnionRule<Types, T, E> &
410
+ ResultRule<Types, T>),
411
+ ): SourceField<S, R | AR, C>
412
+ }
413
+
414
+ export type SourceIssue<Types, S, K, F> = F extends {
415
+ readonly [defaultRef]: infer T
416
+ }
417
+ ? K extends keyof S
418
+ ? [S[K]] extends [Value<Types, T>]
419
+ ? never
420
+ : { readonly source: S[K]; readonly declared: Value<Types, T> }
421
+ : { readonly key: K }
422
+ : never
423
+
424
+ export type CheckedFields<Types, N extends string, S, F> = {
425
+ readonly [K in keyof F]: [SourceIssue<Types, S, K, F[K]>] extends [never]
426
+ ? unknown
427
+ : `${N}.${K & string}: ${DefaultMessage<S, K, F[K]>}`
428
+ }
429
+
430
+ export interface EnumFields<Types, C, K = undefined> {
431
+ // Keep shorthand first: the broader overload widens literal returns before TS7 checks them.
432
+ <
433
+ const N extends string,
434
+ S,
435
+ const T extends NamesOfKind<Types, "enum">,
436
+ const A extends string,
437
+ >(
438
+ ...args: FieldArguments<
439
+ K,
440
+ N,
441
+ T &
442
+ ([NoInfer<A>] extends [ModelAt<Types, NoInfer<T>>]
443
+ ? unknown
444
+ : "Return a registered enum model literal"),
445
+ (source: FieldSource<K, S>, args: {}, context: C) => A
446
+ >
447
+ ): FieldResult<K, N, S, never, C>
448
+ }
449
+
450
+ export interface SubscriptionFields<Types, G, C, K = undefined> {
451
+ <
452
+ const N extends string,
453
+ S,
454
+ const T extends Ref<Types>,
455
+ R = never,
456
+ const Args extends ArgFields = {},
457
+ AR = never,
458
+ >(
459
+ ...args: FieldArguments<
460
+ K,
461
+ N,
462
+ T,
463
+ SubscriptionConfig<
464
+ FieldSource<K, S>,
465
+ Args,
466
+ Value<Types, NoInfer<T>>,
467
+ G,
468
+ R,
469
+ AR,
470
+ C
471
+ >
472
+ >
473
+ ): FieldResult<K, N, S, R | AR, C, true>
474
+ }
475
+
476
+ type ResolverInput<
477
+ Types,
478
+ T,
479
+ S,
480
+ R,
481
+ G,
482
+ E extends readonly ErrorSchema[],
483
+ Args extends ArgFields,
484
+ AR,
485
+ CR,
486
+ C,
487
+ > =
488
+ T extends ConnectionRef<infer N>
489
+ ? ConnectionInput<S, ModelAt<Types, N>, R, G, Args, AR, CR, C>
490
+ : T extends { readonly kind: "list" }
491
+ ? FieldInput<S, Value<Types, T>, R, G, Args, AR, C>
492
+ :
493
+ | Resolve<S, {}, Value<Types, NoInfer<T>>, NoInfer<G>, R, C>
494
+ | (UnionFieldConfig<
495
+ S,
496
+ Args,
497
+ Value<Types, NoInfer<T>>,
498
+ E,
499
+ R,
500
+ NoInfer<G>,
501
+ AR,
502
+ C
503
+ > &
504
+ UnionRule<Types, T, E> &
505
+ ResultRule<Types, T>)
506
+
507
+ export interface ResolverFields<Types, G, C, K = undefined> {
508
+ <
509
+ const N extends string,
510
+ S,
511
+ const T extends
512
+ | Ref<Types>
513
+ | (K extends RootKind ? ConnectionRef<ConnectionNode<Types>> : never),
514
+ R = never,
515
+ const E extends readonly ErrorSchema[] = readonly [],
516
+ const Args extends ArgFields = {},
517
+ AR = never,
518
+ CR = never,
519
+ >(
520
+ ...args: FieldArguments<
521
+ K,
522
+ N,
523
+ T,
524
+ ResolverInput<
525
+ Types,
526
+ NoInfer<T>,
527
+ FieldSource<K, S>,
528
+ R,
529
+ G,
530
+ E,
531
+ Args,
532
+ AR,
533
+ CR,
534
+ C
535
+ >
536
+ >
537
+ ): FieldResult<K, N, S, R | AR | CR, C>
538
+ }
539
+
540
+ export type ObjectFields<Types, G, C> = EnumFields<Types, C> &
541
+ DefaultFields<Types, G, C> &
542
+ ResolverFields<Types, G, C>
543
+
544
+ export interface DefaultFields<Types, G, C> {
545
+ <S, const T extends Ref<Types>, AR = never>(
546
+ type: T,
547
+ options?: DefaultOptions<S, G, AR, C>,
548
+ ): SourceDefault<S, AR, T, C>
549
+ }
550
+
551
+ type ConnectionInput<S, A, R, G, Args extends ArgFields, AR, CR, C> =
552
+ | Resolve<S, ConnectionArgs, Connection<A>, NoInfer<G>, R, C>
553
+ | PagedConnection<S, A, Args, R, NoInfer<G>, AR, CR, C>
554
+ | NodesConnection<S, A, Args, R, NoInfer<G>, AR, CR, C>
555
+
556
+ export interface ObjectConnections<Types, G, C> {
557
+ <const N extends ConnectionNode<Types>>(
558
+ node: N,
559
+ ): ConnectionRef<N> & SourceDefault<unknown, never, `${N}Connection`, C>
560
+ <S, const N extends ConnectionNode<Types>, AR = never>(
561
+ node: N,
562
+ options: DefaultOptions<S, G, AR, C> | undefined,
563
+ ): SourceDefault<S, AR, `${N}Connection`, C>
564
+ <
565
+ S,
566
+ const N extends ConnectionNode<Types>,
567
+ R = never,
568
+ const Args extends ArgFields = {},
569
+ AR = never,
570
+ CR = never,
571
+ >(
572
+ node: N,
573
+ input: ConnectionInput<
574
+ S,
575
+ ModelAt<Types, NoInfer<N>>,
576
+ R,
577
+ G,
578
+ Args,
579
+ AR,
580
+ CR,
581
+ C
582
+ >,
583
+ ): SourceField<S, R | AR | CR, C>
584
+ }
585
+
586
+ /** Field helpers of a builder; `id` covers both the output field and ID arguments. */
587
+ export interface Fields<Types, G, C = {}> extends Omit<
588
+ ScalarHelpers<Types, G, C>,
589
+ "id"
590
+ > {
591
+ /** A non-null `ID` output field read from the source or resolved by `authorize`. */
592
+ id<S, AR = never>(
593
+ options?: DefaultOptions<S, G, AR, C>,
594
+ ): SourceDefault<S, AR, "ID", C>
595
+ /** Exposes a string schema, such as a branded ID, as a GraphQL `ID` argument or input field. */
596
+ id<S extends Schema.Top & Schema.Schema<string>>(schema: S): S["Rebuild"]
597
+ readonly field: ObjectFields<Types, G, C>
598
+ list<const T extends Ref<Types>>(
599
+ of: T,
600
+ ): OutputRef<ListOf<Types, T>> & { readonly kind: "list" } & SourceDefault<
601
+ unknown,
602
+ never,
603
+ OutputRef<ListOf<Types, T>>,
604
+ C
605
+ >
606
+ list<S, const T extends Ref<Types>, AR = never>(
607
+ of: T,
608
+ options: DefaultOptions<S, G, AR, C>,
609
+ ): SourceDefault<S, AR, OutputRef<ListOf<Types, T>>, C>
610
+ list<
611
+ S,
612
+ const T extends Ref<Types>,
613
+ R = never,
614
+ const Args extends ArgFields = {},
615
+ AR = never,
616
+ >(
617
+ of: T,
618
+ input: FieldInput<S, ListOf<Types, NoInfer<T>>, R, G, Args, AR, C>,
619
+ ): SourceField<S, R | AR, C>
620
+ readonly nullable: NullableFields<Types, G, C>
621
+ readonly connection: ObjectConnections<Types, G, C>
622
+ }
623
+
624
+ export type SourceBase<A> = [A] extends [never]
625
+ ? "never"
626
+ : [A] extends [string]
627
+ ? "string"
628
+ : [A] extends [number]
629
+ ? "number"
630
+ : [A] extends [boolean]
631
+ ? "boolean"
632
+ : [A] extends [Date]
633
+ ? "Date"
634
+ : [A] extends [Option.Option<unknown>]
635
+ ? "Option"
636
+ : [A] extends [ReadonlyArray<unknown>]
637
+ ? "ReadonlyArray"
638
+ : "object"
639
+
640
+ export type SourceDescription<A> =
641
+ `${SourceBase<NonNullable<A>>}${null extends A ? " | null" : ""}${undefined extends A ? " | undefined" : ""}`
642
+
643
+ export type DefaultMessage<S, K, F> = K extends keyof S
644
+ ? F extends { readonly [defaultRef]: infer T }
645
+ ? `model has ${SourceDescription<S[K]>}, field declares ${T extends string ? T : T extends OutputRef<infer A, unknown> ? SourceDescription<A> : "declared GraphQL value"}`
646
+ : never
647
+ : "missing source property; supply a resolver"
648
+
649
+ export type RequirementsOfFields<F> = [keyof F] extends [never]
650
+ ? never
651
+ : F[keyof F] extends {
652
+ readonly [fieldRequirements]: infer R
653
+ }
654
+ ? Exclude<R, undefined>
655
+ : never
656
+
657
+ export type Requirements<M> = M[keyof M] extends infer D
658
+ ? D extends { readonly "~kind": string; readonly fields: infer F }
659
+ ? RequirementsOfFields<F>
660
+ : never
661
+ : never
662
+
663
+ export interface Contextual<C> {
664
+ readonly "~context"?: (context: C) => C
665
+ }
666
+
667
+ export type RuntimeField = Pick<Field<unknown>, "kind" | "build">