gql.tada 1.10.1 → 1.11.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.
@@ -0,0 +1,2499 @@
1
+ import { Kind, OperationTypeNode, DocumentNode, DefinitionNode } from '@0no-co/graphql.web';
2
+
3
+ /** Returns `T` if it matches `Constraint` without being equal to it. Failing this evaluates to `Fallback` otherwise. */
4
+ type matchOr<Constraint, T, Fallback> = Constraint extends T
5
+ ? Fallback
6
+ : T extends Constraint
7
+ ? T
8
+ : Fallback;
9
+ /** Flattens a given object type.
10
+ *
11
+ * @remarks
12
+ * This is typically used to make a TypeScript type appear as a flat object,
13
+ * both in terms of type checking and for type hints and the tsserver output.
14
+ */
15
+ type obj<T> = T extends {
16
+ [key: string | number]: any;
17
+ }
18
+ ? {
19
+ [K in keyof T]: T[K];
20
+ }
21
+ : never;
22
+ /** Turns a given union to an intersection type. */
23
+ type overload<T> = (T extends any ? (x: T) => void : never) extends (x: infer U) => void
24
+ ? U & T
25
+ : never;
26
+ /** Annotations for GraphQL’s `DocumentNode` with attached generics for its result data and variables types.
27
+ *
28
+ * @remarks
29
+ * A GraphQL {@link DocumentNode} defines both the variables it accepts on request and the `data`
30
+ * shape it delivers on a response in the GraphQL query language.
31
+ *
32
+ * To bridge the gap to TypeScript, tools may be used to generate TypeScript types that define the shape
33
+ * of `data` and `variables` ahead of time. These types are then attached to GraphQL documents using this
34
+ * `TypedDocumentNode` type.
35
+ *
36
+ * Using a `DocumentNode` that is typed like this will cause any `urql` API to type its input `variables`
37
+ * and resulting `data` using the types provided.
38
+ *
39
+ * @privateRemarks
40
+ * For compatibility reasons this type has been copied and internalized from:
41
+ * https://github.com/dotansimha/graphql-typed-document-node/blob/3711b12/packages/core/src/index.ts#L3-L10
42
+ *
43
+ * @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information.
44
+ */
45
+ interface DocumentDecoration<Result = any, Variables = any> {
46
+ /** Type to support `@graphql-typed-document-node/core`
47
+ * @internal
48
+ */
49
+ __apiType?: (variables: Variables) => Result;
50
+ /** Type to support `TypedQueryDocumentNode` from `graphql`
51
+ * @internal
52
+ */
53
+ __ensureTypesOfVariablesAndResultMatching?: (variables: Variables) => Result;
54
+ }
55
+
56
+ /** Format of introspection data queryied from your schema.
57
+ *
58
+ * @remarks
59
+ * You must provide your introspected schema in the standard introspection
60
+ * format (as represented by this type) to `setupSchema` to configure this
61
+ * library to use your types.
62
+ *
63
+ * @see {@link setupSchema} for where to use this data.
64
+ */
65
+ interface IntrospectionQuery {
66
+ /** This identifies the schema in a "multi-schema" configuration */
67
+ readonly name?: string;
68
+ readonly __schema: IntrospectionSchema;
69
+ }
70
+ interface IntrospectionSchema {
71
+ readonly queryType: IntrospectionNamedTypeRef;
72
+ readonly mutationType?: IntrospectionNamedTypeRef | null;
73
+ readonly subscriptionType?: IntrospectionNamedTypeRef | null;
74
+ readonly types: readonly any[];
75
+ }
76
+ interface IntrospectionObjectType {
77
+ readonly kind: 'OBJECT';
78
+ readonly name: string;
79
+ readonly fields: readonly any[];
80
+ }
81
+ interface IntrospectionInterfaceType {
82
+ readonly kind: 'INTERFACE';
83
+ readonly name: string;
84
+ readonly fields: readonly any[];
85
+ readonly possibleTypes: readonly any[];
86
+ }
87
+ interface IntrospectionUnionType {
88
+ readonly kind: 'UNION';
89
+ readonly name: string;
90
+ readonly possibleTypes: readonly any[];
91
+ }
92
+ interface IntrospectionEnumType {
93
+ readonly kind: 'ENUM';
94
+ readonly name: string;
95
+ readonly enumValues: readonly any[];
96
+ }
97
+ interface IntrospectionInputObjectType {
98
+ readonly kind: 'INPUT_OBJECT';
99
+ readonly name: string;
100
+ readonly isOneOf?: boolean;
101
+ readonly inputFields: readonly any[];
102
+ }
103
+ interface IntrospectionListTypeRef {
104
+ readonly kind: 'LIST';
105
+ readonly ofType: IntrospectionTypeRef;
106
+ }
107
+ interface IntrospectionNonNullTypeRef {
108
+ readonly kind: 'NON_NULL';
109
+ readonly ofType: IntrospectionTypeRef;
110
+ }
111
+ type IntrospectionTypeRef =
112
+ | IntrospectionNamedTypeRef
113
+ | IntrospectionListTypeRef
114
+ | IntrospectionNonNullTypeRef;
115
+ interface IntrospectionNamedTypeRef {
116
+ readonly name: string;
117
+ }
118
+ interface IntrospectionField {
119
+ readonly name: string;
120
+ readonly type: IntrospectionTypeRef;
121
+ }
122
+ interface DefaultScalars {
123
+ readonly ID: string;
124
+ readonly Boolean: boolean;
125
+ readonly String: string;
126
+ readonly Float: number;
127
+ readonly Int: number;
128
+ }
129
+ type mapEnum<T extends IntrospectionEnumType> = {
130
+ name: T['name'];
131
+ enumValues: T['enumValues'][number]['name'];
132
+ };
133
+ type mapField<T> = T extends IntrospectionField
134
+ ? {
135
+ name: T['name'];
136
+ type: T['type'];
137
+ }
138
+ : never;
139
+ type mapObject<T extends IntrospectionObjectType> = {
140
+ kind: 'OBJECT';
141
+ name: T['name'];
142
+ fields: obj<{
143
+ [P in T['fields'][number]['name']]: T['fields'][number] extends infer Field
144
+ ? Field extends {
145
+ readonly name: P;
146
+ }
147
+ ? mapField<Field>
148
+ : never
149
+ : never;
150
+ }>;
151
+ };
152
+ type mapInputObject<T extends IntrospectionInputObjectType> = {
153
+ kind: 'INPUT_OBJECT';
154
+ name: T['name'];
155
+ isOneOf: T['isOneOf'] extends boolean ? T['isOneOf'] : false;
156
+ inputFields: [...T['inputFields']];
157
+ };
158
+ type mapInterface<T extends IntrospectionInterfaceType> = {
159
+ kind: 'INTERFACE';
160
+ name: T['name'];
161
+ possibleTypes: T['possibleTypes'][number]['name'];
162
+ fields: obj<{
163
+ [P in T['fields'][number]['name']]: T['fields'][number] extends infer Field
164
+ ? Field extends {
165
+ readonly name: P;
166
+ }
167
+ ? mapField<Field>
168
+ : never
169
+ : never;
170
+ }>;
171
+ };
172
+ type mapUnion<T extends IntrospectionUnionType> = {
173
+ kind: 'UNION';
174
+ name: T['name'];
175
+ fields: {};
176
+ possibleTypes: T['possibleTypes'][number]['name'];
177
+ };
178
+ /** @internal */
179
+ type mapType<Type> = Type extends IntrospectionEnumType
180
+ ? mapEnum<Type>
181
+ : Type extends IntrospectionObjectType
182
+ ? mapObject<Type>
183
+ : Type extends IntrospectionInterfaceType
184
+ ? mapInterface<Type>
185
+ : Type extends IntrospectionUnionType
186
+ ? mapUnion<Type>
187
+ : Type extends IntrospectionInputObjectType
188
+ ? mapInputObject<Type>
189
+ : unknown;
190
+ /** @internal */
191
+ type mapIntrospectionTypes<Query extends IntrospectionQuery> = obj<{
192
+ [P in Query['__schema']['types'][number]['name']]: Query['__schema']['types'][number] extends infer Type
193
+ ? Type extends {
194
+ readonly name: P;
195
+ }
196
+ ? mapType<Type>
197
+ : never
198
+ : never;
199
+ }>;
200
+ /** @internal */
201
+ type mapIntrospectionScalarTypes<Scalars extends ScalarsLike = DefaultScalars> = obj<{
202
+ [P in keyof Scalars | keyof DefaultScalars]: {
203
+ name: P;
204
+ type: P extends keyof Scalars
205
+ ? Scalars[P]
206
+ : P extends keyof DefaultScalars
207
+ ? DefaultScalars[P]
208
+ : never;
209
+ };
210
+ }>;
211
+ /** @internal */
212
+ type mapIntrospection<Query extends IntrospectionLikeInput> = Query extends IntrospectionQuery
213
+ ? {
214
+ name: Query['name'];
215
+ query: Query['__schema']['queryType']['name'];
216
+ mutation: Query['__schema']['mutationType'] extends {
217
+ name: string;
218
+ }
219
+ ? Query['__schema']['mutationType']['name']
220
+ : never;
221
+ subscription: Query['__schema']['subscriptionType'] extends {
222
+ name: string;
223
+ }
224
+ ? Query['__schema']['subscriptionType']['name']
225
+ : never;
226
+ types: mapIntrospectionTypes<Query>;
227
+ }
228
+ : Query;
229
+ type addIntrospectionScalars<
230
+ Schema extends SchemaLike,
231
+ Scalars extends ScalarsLike = DefaultScalars,
232
+ > = {
233
+ name: Schema['name'];
234
+ query: Schema['query'];
235
+ mutation: Schema['mutation'];
236
+ subscription: Schema['subscription'];
237
+ types: mapIntrospectionScalarTypes<Scalars> & Schema['types'];
238
+ };
239
+ /** Either a format of introspection data or an already preprocessed schema.
240
+ * @see {@link IntrospectionQuery} */
241
+ type IntrospectionLikeInput = SchemaLike | IntrospectionQuery;
242
+ type ScalarsLike = {
243
+ readonly [name: string]: any;
244
+ };
245
+ type SchemaLike = {
246
+ name?: any;
247
+ query: string;
248
+ mutation?: any;
249
+ subscription?: any;
250
+ types: {
251
+ [name: string]: any;
252
+ };
253
+ };
254
+
255
+ declare const enum Token {
256
+ Name = 0,
257
+ Var = 1,
258
+ Directive = 2,
259
+ Spread = 3,
260
+ Exclam = 4,
261
+ Equal = 5,
262
+ Colon = 6,
263
+ BraceOpen = 7,
264
+ BraceClose = 8,
265
+ ParenOpen = 9,
266
+ ParenClose = 10,
267
+ BracketOpen = 11,
268
+ BracketClose = 12,
269
+ BlockString = 13,
270
+ String = 14,
271
+ Integer = 15,
272
+ Float = 16,
273
+ }
274
+ interface _match$1<Out extends string, In extends string> {
275
+ out: Out;
276
+ in: In;
277
+ }
278
+ type ignored = ' ' | '\n' | '\t' | '\r' | ',' | '\ufeff';
279
+ type digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';
280
+ type letter =
281
+ | 'A'
282
+ | 'B'
283
+ | 'C'
284
+ | 'D'
285
+ | 'E'
286
+ | 'F'
287
+ | 'G'
288
+ | 'H'
289
+ | 'I'
290
+ | 'J'
291
+ | 'K'
292
+ | 'L'
293
+ | 'M'
294
+ | 'N'
295
+ | 'O'
296
+ | 'P'
297
+ | 'Q'
298
+ | 'R'
299
+ | 'S'
300
+ | 'T'
301
+ | 'U'
302
+ | 'V'
303
+ | 'W'
304
+ | 'X'
305
+ | 'Y'
306
+ | 'Z'
307
+ | 'a'
308
+ | 'b'
309
+ | 'c'
310
+ | 'd'
311
+ | 'e'
312
+ | 'f'
313
+ | 'g'
314
+ | 'h'
315
+ | 'i'
316
+ | 'j'
317
+ | 'k'
318
+ | 'l'
319
+ | 'm'
320
+ | 'n'
321
+ | 'o'
322
+ | 'p'
323
+ | 'q'
324
+ | 'r'
325
+ | 's'
326
+ | 't'
327
+ | 'u'
328
+ | 'v'
329
+ | 'w'
330
+ | 'x'
331
+ | 'y'
332
+ | 'z';
333
+ type skipIgnored<In> = In extends `#${infer _}\n${infer In}`
334
+ ? skipIgnored<In>
335
+ : In extends `#${infer _}`
336
+ ? ''
337
+ : In extends ` ${infer In}`
338
+ ? skipIgnored<In>
339
+ : In extends `\n${infer In}`
340
+ ? skipIgnored<In>
341
+ : In extends `\t${infer In}`
342
+ ? skipIgnored<In>
343
+ : In extends `\r${infer In}`
344
+ ? skipIgnored<In>
345
+ : In extends `,${infer In}`
346
+ ? skipIgnored<In>
347
+ : In extends `\ufeff${infer In}`
348
+ ? skipIgnored<In>
349
+ : In;
350
+ type skipDigits<In> = In extends `${digit}${infer In}` ? skipDigits<In> : In;
351
+ type skipFloat<In> = In extends `${'.'}${infer In}`
352
+ ? skipDigits<In> extends `${'e' | 'E'}${infer In}`
353
+ ? skipDigits<In extends `${'+' | '-'}${infer In}` ? In : In>
354
+ : skipDigits<In>
355
+ : skipDigits<In> extends `${'e' | 'E'}${infer In}`
356
+ ? skipDigits<In extends `${'+' | '-'}${infer In}` ? In : In>
357
+ : void;
358
+ type skipBlockString<In> = In extends `${infer Hd}${'"""'}${infer In}`
359
+ ? Hd extends `${string}${'\\'}`
360
+ ? skipBlockString<In>
361
+ : In
362
+ : In;
363
+ type skipString<In> = In extends `${infer Hd}${'"'}${infer In}`
364
+ ? Hd extends `${string}${'\\'}`
365
+ ? skipString<In>
366
+ : In
367
+ : In;
368
+ type takeNameLiteralRec<
369
+ PrevMatch extends string,
370
+ In extends string,
371
+ > = In extends `${infer Match}${infer Out}`
372
+ ? Match extends letter | digit | '_'
373
+ ? takeNameLiteralRec<`${PrevMatch}${Match}`, Out>
374
+ : _match$1<PrevMatch, In>
375
+ : _match$1<PrevMatch, In>;
376
+ interface VarTokenNode<Name extends string = string> {
377
+ kind: Token.Var;
378
+ name: Name;
379
+ }
380
+ interface NameTokenNode<Name extends string = string> {
381
+ kind: Token.Name;
382
+ name: Name;
383
+ }
384
+ interface DirectiveTokenNode<Name extends string = string> {
385
+ kind: Token.Directive;
386
+ name: Name;
387
+ }
388
+ type TokenNode = Token | NameTokenNode | VarTokenNode | DirectiveTokenNode;
389
+ interface _state<In extends string, Out extends TokenNode[]> {
390
+ out: Out;
391
+ in: In;
392
+ }
393
+ interface _punctuator {
394
+ '!': Token.Exclam;
395
+ '=': Token.Equal;
396
+ ':': Token.Colon;
397
+ '{': Token.BraceOpen;
398
+ '}': Token.BraceClose;
399
+ '(': Token.ParenOpen;
400
+ ')': Token.ParenClose;
401
+ '[': Token.BracketOpen;
402
+ ']': Token.BracketClose;
403
+ }
404
+ type tokenizeStep<State> =
405
+ State extends _state<'', any>
406
+ ? State
407
+ : State extends _state<infer In, infer Out>
408
+ ? In extends `#${string}`
409
+ ? _state<skipIgnored<In>, Out>
410
+ : In extends `${infer Char}${infer Rest}`
411
+ ? Char extends ignored
412
+ ? _state<skipIgnored<In>, Out>
413
+ : Char extends keyof _punctuator
414
+ ? _state<Rest, [...Out, _punctuator[Char]]>
415
+ : Char extends '"'
416
+ ? In extends `"""${infer In}`
417
+ ? _state<skipBlockString<In>, [...Out, Token.BlockString]>
418
+ : In extends `"${infer In}`
419
+ ? _state<skipString<In>, [...Out, Token.String]>
420
+ : void
421
+ : Char extends '.'
422
+ ? In extends `...${infer In}`
423
+ ? _state<In, [...Out, Token.Spread]>
424
+ : void
425
+ : Char extends '$'
426
+ ? takeNameLiteralRec<'', Rest> extends _match$1<infer Match, infer In>
427
+ ? _state<In, [...Out, VarTokenNode<Match>]>
428
+ : void
429
+ : Char extends '@'
430
+ ? takeNameLiteralRec<'', Rest> extends _match$1<infer Match, infer In>
431
+ ? _state<In, [...Out, DirectiveTokenNode<Match>]>
432
+ : void
433
+ : Char extends '-' | digit
434
+ ? In extends `-${digit}${infer In}`
435
+ ? skipFloat<skipDigits<In>> extends `${infer In}`
436
+ ? _state<In, [...Out, Token.Float]>
437
+ : _state<skipDigits<In>, [...Out, Token.Integer]>
438
+ : In extends `${digit}${infer In}`
439
+ ? skipFloat<skipDigits<In>> extends `${infer In}`
440
+ ? _state<In, [...Out, Token.Float]>
441
+ : _state<skipDigits<In>, [...Out, Token.Integer]>
442
+ : void
443
+ : Char extends letter | '_'
444
+ ? takeNameLiteralRec<Char, Rest> extends _match$1<infer Match, infer In>
445
+ ? _state<In, [...Out, NameTokenNode<Match>]>
446
+ : void
447
+ : void
448
+ : void
449
+ : void;
450
+ type tokenizeStep4<State> = tokenizeStep<tokenizeStep<tokenizeStep<tokenizeStep<State>>>>;
451
+ type tokenizeRec<State> =
452
+ State extends _state<'', any>
453
+ ? State['out']
454
+ : State extends _state<any, any>
455
+ ? tokenizeRec<tokenizeStep4<State>>
456
+ : [];
457
+ type tokenize<In extends string> = tokenizeRec<_state<In, []>>;
458
+
459
+ interface _match<Out, In extends any[]> {
460
+ out: Out;
461
+ in: In;
462
+ }
463
+ interface _match2<Out1, Out2, In extends any[]> {
464
+ out1: Out1;
465
+ out2: Out2;
466
+ in: In;
467
+ }
468
+ type takeOptionalName<In extends any[]> = In extends [
469
+ {
470
+ kind: Token.Name;
471
+ name: infer Name;
472
+ },
473
+ ...infer In,
474
+ ]
475
+ ? _match<
476
+ {
477
+ kind: Kind.NAME;
478
+ value: Name;
479
+ },
480
+ In
481
+ >
482
+ : _match<undefined, In>;
483
+ type takeValue<In extends any[], Const extends boolean> = In extends [infer Head, ...infer In]
484
+ ? Head extends Token.Float
485
+ ? _match<
486
+ {
487
+ kind: Kind.FLOAT;
488
+ value: string;
489
+ },
490
+ In
491
+ >
492
+ : Head extends Token.Integer
493
+ ? _match<
494
+ {
495
+ kind: Kind.INT;
496
+ value: string;
497
+ },
498
+ In
499
+ >
500
+ : Head extends Token.String
501
+ ? _match<
502
+ {
503
+ kind: Kind.STRING;
504
+ value: string;
505
+ block: false;
506
+ },
507
+ In
508
+ >
509
+ : Head extends Token.BlockString
510
+ ? _match<
511
+ {
512
+ kind: Kind.STRING;
513
+ value: string;
514
+ block: true;
515
+ },
516
+ In
517
+ >
518
+ : Head extends {
519
+ kind: Token.Name;
520
+ name: infer Name;
521
+ }
522
+ ? Name extends 'null'
523
+ ? _match<
524
+ {
525
+ kind: Kind.NULL;
526
+ },
527
+ In
528
+ >
529
+ : Name extends 'true' | 'false'
530
+ ? _match<
531
+ {
532
+ kind: Kind.BOOLEAN;
533
+ value: boolean;
534
+ },
535
+ In
536
+ >
537
+ : _match<
538
+ {
539
+ kind: Kind.ENUM;
540
+ value: Name;
541
+ },
542
+ In
543
+ >
544
+ : Head extends Token.BracketOpen
545
+ ? takeListRec<[], In, Const>
546
+ : Head extends Token.BraceOpen
547
+ ? takeObjectRec<[], In, Const>
548
+ : Const extends false
549
+ ? Head extends {
550
+ kind: Token.Var;
551
+ name: infer Name;
552
+ }
553
+ ? _match<
554
+ {
555
+ kind: Kind.VARIABLE;
556
+ name: {
557
+ kind: Kind.NAME;
558
+ value: Name;
559
+ };
560
+ },
561
+ In
562
+ >
563
+ : void
564
+ : void
565
+ : void;
566
+ type takeListRec<Nodes extends any[], In extends any[], Const extends boolean> = In extends [
567
+ Token.BracketClose,
568
+ ...infer In,
569
+ ]
570
+ ? _match<
571
+ {
572
+ kind: Kind.LIST;
573
+ values: Nodes;
574
+ },
575
+ In
576
+ >
577
+ : takeValue<In, Const> extends _match<infer Node, infer In>
578
+ ? takeListRec<[...Nodes, Node], In, Const>
579
+ : void;
580
+ type takeObjectField<In extends any[], Const extends boolean> = In extends [
581
+ {
582
+ kind: Token.Name;
583
+ name: infer FieldName;
584
+ },
585
+ Token.Colon,
586
+ ...infer In,
587
+ ]
588
+ ? takeValue<In, Const> extends _match<infer Value, infer In>
589
+ ? _match<
590
+ {
591
+ kind: Kind.OBJECT_FIELD;
592
+ name: {
593
+ kind: Kind.NAME;
594
+ value: FieldName;
595
+ };
596
+ value: Value;
597
+ },
598
+ In
599
+ >
600
+ : void
601
+ : void;
602
+ type takeObjectRec<Fields extends any[], In extends any[], Const extends boolean> = In extends [
603
+ Token.BraceClose,
604
+ ...infer In,
605
+ ]
606
+ ? _match<
607
+ {
608
+ kind: Kind.OBJECT;
609
+ fields: Fields;
610
+ },
611
+ In
612
+ >
613
+ : takeObjectField<In, Const> extends _match<infer Field, infer In>
614
+ ? takeObjectRec<[...Fields, Field], In, Const>
615
+ : void;
616
+ type takeArgument<In extends any[], Const extends boolean> = In extends [
617
+ {
618
+ kind: Token.Name;
619
+ name: infer ArgName;
620
+ },
621
+ Token.Colon,
622
+ ...infer In,
623
+ ]
624
+ ? takeValue<In, Const> extends _match<infer Value, infer In>
625
+ ? _match<
626
+ {
627
+ kind: Kind.ARGUMENT;
628
+ name: {
629
+ kind: Kind.NAME;
630
+ value: ArgName;
631
+ };
632
+ value: Value;
633
+ },
634
+ In
635
+ >
636
+ : void
637
+ : void;
638
+ type _takeArgumentsRec<
639
+ Arguments extends any[],
640
+ In extends any[],
641
+ Const extends boolean,
642
+ > = In extends [Token.ParenClose, ...infer In]
643
+ ? _match<Arguments, In>
644
+ : takeArgument<In, Const> extends _match<infer Argument, infer In>
645
+ ? _takeArgumentsRec<[...Arguments, Argument], In, Const>
646
+ : void;
647
+ type takeArguments<In extends any[], Const extends boolean> = In extends [
648
+ Token.ParenOpen,
649
+ ...infer In,
650
+ ]
651
+ ? _takeArgumentsRec<[], In, Const>
652
+ : _match<[], In>;
653
+ type takeDirective<In extends any[], Const extends boolean> = In extends [
654
+ {
655
+ kind: Token.Directive;
656
+ name: infer DirectiveName;
657
+ },
658
+ ...infer In,
659
+ ]
660
+ ? takeArguments<In, Const> extends _match<infer Arguments, infer In>
661
+ ? _match<
662
+ {
663
+ kind: Kind.DIRECTIVE;
664
+ name: {
665
+ kind: Kind.NAME;
666
+ value: DirectiveName;
667
+ };
668
+ arguments: Arguments;
669
+ },
670
+ In
671
+ >
672
+ : void
673
+ : void;
674
+ type takeDirectives<
675
+ In extends any[],
676
+ Const extends boolean,
677
+ Directives extends any[] = [],
678
+ > = In extends [
679
+ {
680
+ kind: Token.Directive;
681
+ },
682
+ ...any[],
683
+ ]
684
+ ? takeDirective<In, Const> extends _match<infer Directive, infer In>
685
+ ? takeDirectives<In, Const, [...Directives, Directive]>
686
+ : _match<Directives, In>
687
+ : _match<Directives, In>;
688
+ type _takeFieldName<In extends any[]> = In extends [
689
+ {
690
+ kind: Token.Name;
691
+ name: infer MaybeAlias;
692
+ },
693
+ ...infer In,
694
+ ]
695
+ ? In extends [
696
+ Token.Colon,
697
+ {
698
+ kind: Token.Name;
699
+ name: infer Name;
700
+ },
701
+ ...infer In,
702
+ ]
703
+ ? _match2<
704
+ {
705
+ kind: Kind.NAME;
706
+ value: MaybeAlias;
707
+ },
708
+ {
709
+ kind: Kind.NAME;
710
+ value: Name;
711
+ },
712
+ In
713
+ >
714
+ : _match2<
715
+ undefined,
716
+ {
717
+ kind: Kind.NAME;
718
+ value: MaybeAlias;
719
+ },
720
+ In
721
+ >
722
+ : void;
723
+ type _takeField<In extends any[]> =
724
+ _takeFieldName<In> extends _match2<infer Alias, infer Name, infer In>
725
+ ? takeArguments<In, false> extends _match<infer Arguments, infer In>
726
+ ? takeDirectives<In, false> extends _match<infer Directives, infer In>
727
+ ? In extends [Token.BraceOpen, ...any[]]
728
+ ? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
729
+ ? _match<
730
+ {
731
+ kind: Kind.FIELD;
732
+ alias: Alias;
733
+ name: Name;
734
+ arguments: Arguments;
735
+ directives: Directives;
736
+ selectionSet: SelectionSet;
737
+ },
738
+ In
739
+ >
740
+ : void
741
+ : _match<
742
+ {
743
+ kind: Kind.FIELD;
744
+ alias: Alias;
745
+ name: Name;
746
+ arguments: Arguments;
747
+ directives: Directives;
748
+ selectionSet: undefined;
749
+ },
750
+ In
751
+ >
752
+ : void
753
+ : void
754
+ : void;
755
+ type _takeFragmentSpread<In extends any[]> = In extends [Token.Spread, ...infer In]
756
+ ? In extends [
757
+ {
758
+ kind: Token.Name;
759
+ name: 'on';
760
+ },
761
+ {
762
+ kind: Token.Name;
763
+ name: infer Type;
764
+ },
765
+ ...infer In,
766
+ ]
767
+ ? takeDirectives<In, false> extends _match<infer Directives, infer In>
768
+ ? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
769
+ ? _match<
770
+ {
771
+ kind: Kind.INLINE_FRAGMENT;
772
+ typeCondition: {
773
+ kind: Kind.NAMED_TYPE;
774
+ name: {
775
+ kind: Kind.NAME;
776
+ value: Type;
777
+ };
778
+ };
779
+ directives: Directives;
780
+ selectionSet: SelectionSet;
781
+ },
782
+ In
783
+ >
784
+ : void
785
+ : void
786
+ : In extends [
787
+ {
788
+ kind: Token.Name;
789
+ name: infer Name;
790
+ },
791
+ ...infer In,
792
+ ]
793
+ ? takeDirectives<In, false> extends _match<infer Directives, infer In>
794
+ ? _match<
795
+ {
796
+ kind: Kind.FRAGMENT_SPREAD;
797
+ name: {
798
+ kind: Kind.NAME;
799
+ value: Name;
800
+ };
801
+ directives: Directives;
802
+ },
803
+ In
804
+ >
805
+ : void
806
+ : takeDirectives<In, false> extends _match<infer Directives, infer In>
807
+ ? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
808
+ ? _match<
809
+ {
810
+ kind: Kind.INLINE_FRAGMENT;
811
+ typeCondition: undefined;
812
+ directives: Directives;
813
+ selectionSet: SelectionSet;
814
+ },
815
+ In
816
+ >
817
+ : void
818
+ : void
819
+ : void;
820
+ type takeType<In extends any[]> = In extends [Token.BracketOpen, ...infer In]
821
+ ? takeType<In> extends _match<infer Subtype, infer In>
822
+ ? In extends [Token.BracketClose, ...infer In]
823
+ ? In extends [Token.Exclam, ...infer In]
824
+ ? _match<
825
+ {
826
+ kind: Kind.NON_NULL_TYPE;
827
+ type: {
828
+ kind: Kind.LIST_TYPE;
829
+ type: Subtype;
830
+ };
831
+ },
832
+ In
833
+ >
834
+ : _match<
835
+ {
836
+ kind: Kind.LIST_TYPE;
837
+ type: Subtype;
838
+ },
839
+ In
840
+ >
841
+ : void
842
+ : void
843
+ : In extends [
844
+ {
845
+ kind: Token.Name;
846
+ name: infer Name;
847
+ },
848
+ ...infer In,
849
+ ]
850
+ ? In extends [Token.Exclam, ...infer In]
851
+ ? _match<
852
+ {
853
+ kind: Kind.NON_NULL_TYPE;
854
+ type: {
855
+ kind: Kind.NAMED_TYPE;
856
+ name: {
857
+ kind: Kind.NAME;
858
+ value: Name;
859
+ };
860
+ };
861
+ },
862
+ In
863
+ >
864
+ : _match<
865
+ {
866
+ kind: Kind.NAMED_TYPE;
867
+ name: {
868
+ kind: Kind.NAME;
869
+ value: Name;
870
+ };
871
+ },
872
+ In
873
+ >
874
+ : void;
875
+ type _takeSelectionRec<Selections extends any[], In extends any[]> = In extends [
876
+ {
877
+ kind: Token.Name;
878
+ },
879
+ ...any[],
880
+ ]
881
+ ? _takeField<In> extends _match<infer Selection, infer In>
882
+ ? _takeSelectionRec<[...Selections, Selection], In>
883
+ : void
884
+ : In extends [Token.Spread, ...any[]]
885
+ ? _takeFragmentSpread<In> extends _match<infer Selection, infer In>
886
+ ? _takeSelectionRec<[...Selections, Selection], In>
887
+ : void
888
+ : In extends [Token.BraceClose, ...infer In]
889
+ ? _match<
890
+ {
891
+ kind: Kind.SELECTION_SET;
892
+ selections: Selections;
893
+ },
894
+ In
895
+ >
896
+ : void;
897
+ type takeSelectionSet<In extends any[]> = In extends [Token.BraceOpen, ...infer In]
898
+ ? _takeSelectionRec<[], In>
899
+ : void;
900
+ type takeVarDefinition<In extends any[]> = In extends [
901
+ {
902
+ kind: Token.Var;
903
+ name: infer VarName;
904
+ },
905
+ Token.Colon,
906
+ ...infer In,
907
+ ]
908
+ ? takeType<In> extends _match<infer Type, infer In>
909
+ ? In extends [Token.Equal, ...infer In]
910
+ ? takeValue<In, true> extends _match<infer DefaultValue, infer In>
911
+ ? takeDirectives<In, true> extends _match<infer Directives, infer In>
912
+ ? _match<
913
+ {
914
+ kind: Kind.VARIABLE_DEFINITION;
915
+ variable: {
916
+ kind: Kind.VARIABLE;
917
+ name: {
918
+ kind: Kind.NAME;
919
+ value: VarName;
920
+ };
921
+ };
922
+ type: Type;
923
+ defaultValue: DefaultValue;
924
+ directives: Directives;
925
+ },
926
+ In
927
+ >
928
+ : void
929
+ : void
930
+ : takeDirectives<In, true> extends _match<infer Directives, infer In>
931
+ ? _match<
932
+ {
933
+ kind: Kind.VARIABLE_DEFINITION;
934
+ variable: {
935
+ kind: Kind.VARIABLE;
936
+ name: {
937
+ kind: Kind.NAME;
938
+ value: VarName;
939
+ };
940
+ };
941
+ type: Type;
942
+ defaultValue: undefined;
943
+ directives: Directives;
944
+ },
945
+ In
946
+ >
947
+ : void
948
+ : void
949
+ : void;
950
+ type _takeVarDefinitionRec<Definitions extends any[], In extends any[]> = In extends [
951
+ Token.ParenClose,
952
+ ...infer In,
953
+ ]
954
+ ? _match<Definitions, In>
955
+ : In extends [
956
+ {
957
+ kind: Token.Var;
958
+ },
959
+ ...any[],
960
+ ]
961
+ ? takeVarDefinition<In> extends _match<infer Definition, infer In>
962
+ ? _takeVarDefinitionRec<[...Definitions, Definition], In>
963
+ : _match<Definitions, In>
964
+ : In extends [Token.String | Token.BlockString, ...infer In]
965
+ ? _takeVarDefinitionRec<[...Definitions], In>
966
+ : _match<Definitions, In>;
967
+ type takeVarDefinitions<In extends any[]> = In extends [Token.ParenOpen, ...infer In]
968
+ ? _takeVarDefinitionRec<[], In>
969
+ : _match<[], In>;
970
+ type takeFragmentDefinition<In extends any[]> = In extends [
971
+ {
972
+ kind: Token.Name;
973
+ name: 'fragment';
974
+ },
975
+ {
976
+ kind: Token.Name;
977
+ name: infer Name;
978
+ },
979
+ {
980
+ kind: Token.Name;
981
+ name: 'on';
982
+ },
983
+ {
984
+ kind: Token.Name;
985
+ name: infer Type;
986
+ },
987
+ ...infer In,
988
+ ]
989
+ ? takeDirectives<In, true> extends _match<infer Directives, infer In>
990
+ ? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
991
+ ? _match<
992
+ {
993
+ kind: Kind.FRAGMENT_DEFINITION;
994
+ name: {
995
+ kind: Kind.NAME;
996
+ value: Name;
997
+ };
998
+ typeCondition: {
999
+ kind: Kind.NAMED_TYPE;
1000
+ name: {
1001
+ kind: Kind.NAME;
1002
+ value: Type;
1003
+ };
1004
+ };
1005
+ directives: Directives;
1006
+ selectionSet: SelectionSet;
1007
+ },
1008
+ In
1009
+ >
1010
+ : void
1011
+ : void
1012
+ : void;
1013
+ type takeOperation<In extends any[]> = In extends [
1014
+ {
1015
+ kind: Token.Name;
1016
+ name: infer Operation;
1017
+ },
1018
+ ...infer In,
1019
+ ]
1020
+ ? Operation extends 'query'
1021
+ ? _match<OperationTypeNode.QUERY, In>
1022
+ : Operation extends 'mutation'
1023
+ ? _match<OperationTypeNode.MUTATION, In>
1024
+ : Operation extends 'subscription'
1025
+ ? _match<OperationTypeNode.SUBSCRIPTION, In>
1026
+ : void
1027
+ : void;
1028
+ type takeOperationDefinition<In extends any[]> =
1029
+ takeOperation<In> extends _match<infer Operation, infer In>
1030
+ ? takeOptionalName<In> extends _match<infer Name, infer In>
1031
+ ? takeVarDefinitions<In> extends _match<infer VarDefinitions, infer In>
1032
+ ? takeDirectives<In, false> extends _match<infer Directives, infer In>
1033
+ ? takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
1034
+ ? _match<
1035
+ {
1036
+ kind: Kind.OPERATION_DEFINITION;
1037
+ operation: Operation;
1038
+ name: Name;
1039
+ variableDefinitions: VarDefinitions;
1040
+ directives: Directives;
1041
+ selectionSet: SelectionSet;
1042
+ },
1043
+ In
1044
+ >
1045
+ : void
1046
+ : void
1047
+ : void
1048
+ : void
1049
+ : takeSelectionSet<In> extends _match<infer SelectionSet, infer In>
1050
+ ? _match<
1051
+ {
1052
+ kind: Kind.OPERATION_DEFINITION;
1053
+ operation: OperationTypeNode.QUERY;
1054
+ name: undefined;
1055
+ variableDefinitions: [];
1056
+ directives: [];
1057
+ selectionSet: SelectionSet;
1058
+ },
1059
+ In
1060
+ >
1061
+ : void;
1062
+ type _takeDocumentRec<Definitions extends any[], In extends any[]> = In extends [
1063
+ {
1064
+ kind: Token.Name;
1065
+ name: 'fragment';
1066
+ },
1067
+ ...any[],
1068
+ ]
1069
+ ? takeFragmentDefinition<In> extends _match<infer Definition, infer In>
1070
+ ? _takeDocumentRec<[...Definitions, Definition], In>
1071
+ : _match<Definitions, In>
1072
+ : In extends [
1073
+ {
1074
+ kind: Token.Name;
1075
+ name: 'query' | 'mutation' | 'subscription';
1076
+ },
1077
+ ...any[],
1078
+ ]
1079
+ ? takeOperationDefinition<In> extends _match<infer Definition, infer In>
1080
+ ? _takeDocumentRec<[...Definitions, Definition], In>
1081
+ : _match<Definitions, In>
1082
+ : In extends [Token.BraceOpen, ...any[]]
1083
+ ? takeOperationDefinition<In> extends _match<infer Definition, infer In>
1084
+ ? _takeDocumentRec<[...Definitions, Definition], In>
1085
+ : _match<Definitions, In>
1086
+ : In extends [Token.String | Token.BlockString, ...infer In]
1087
+ ? _takeDocumentRec<[...Definitions], In>
1088
+ : _match<Definitions, In>;
1089
+ type parseDocument<In extends string> =
1090
+ _takeDocumentRec<[], tokenize<In>> extends _match<[...infer Definitions], any>
1091
+ ? Definitions extends []
1092
+ ? never
1093
+ : {
1094
+ kind: Kind.DOCUMENT;
1095
+ definitions: Definitions;
1096
+ }
1097
+ : never;
1098
+ type DocumentNodeLike = {
1099
+ kind: Kind.DOCUMENT;
1100
+ definitions: readonly any[];
1101
+ };
1102
+
1103
+ /** Private namespace holding our symbols for markers.
1104
+ * @internal
1105
+ *
1106
+ * @remarks
1107
+ * Markers are used to indicate, for example, which fragments a given GraphQL document
1108
+ * is referring to or which fragments a document exposes. This ties into “fragment masking”,
1109
+ * a process by which the type of a fragment is hidden away until it’s unwrapped, to enforce
1110
+ * isolation and code-reuse.
1111
+ */
1112
+ declare namespace $tada {
1113
+ const fragmentRefs: unique symbol;
1114
+ type fragmentRefs = typeof fragmentRefs;
1115
+ const definition: unique symbol;
1116
+ type definition = typeof definition;
1117
+ const ref: unique symbol;
1118
+ type ref = typeof ref;
1119
+ }
1120
+ interface FragmentDefDecorationLike {
1121
+ fragment: any;
1122
+ on: any;
1123
+ masked: any;
1124
+ }
1125
+ type isMaskedRec<Directives extends readonly unknown[] | undefined> = Directives extends readonly [
1126
+ infer Directive,
1127
+ ...infer Rest,
1128
+ ]
1129
+ ? Directive extends {
1130
+ kind: Kind.DIRECTIVE;
1131
+ name: any;
1132
+ }
1133
+ ? Directive['name']['value'] extends '_unmask'
1134
+ ? false
1135
+ : isMaskedRec<Rest>
1136
+ : isMaskedRec<Rest>
1137
+ : true;
1138
+ type decorateFragmentDef<
1139
+ Document extends DocumentNodeLike,
1140
+ isMaskingDisabled = false,
1141
+ > = Document['definitions'][0] extends {
1142
+ kind: Kind.FRAGMENT_DEFINITION;
1143
+ name: any;
1144
+ }
1145
+ ? {
1146
+ fragment: Document['definitions'][0]['name']['value'];
1147
+ on: Document['definitions'][0]['typeCondition']['name']['value'];
1148
+ masked: isMaskingDisabled extends true
1149
+ ? false
1150
+ : isMaskedRec<Document['definitions'][0]['directives']>;
1151
+ }
1152
+ : void;
1153
+ type getFragmentsOfDocuments<Documents extends readonly FragmentShape[]> = overload<
1154
+ Documents[number] extends infer Document
1155
+ ? Document extends FragmentShape<infer Definition>
1156
+ ? {
1157
+ [P in Definition['fragment']]: {
1158
+ kind: Kind.FRAGMENT_DEFINITION;
1159
+ name: {
1160
+ kind: Kind.NAME;
1161
+ value: Definition['fragment'];
1162
+ };
1163
+ typeCondition: {
1164
+ kind: Kind.NAMED_TYPE;
1165
+ name: {
1166
+ kind: Kind.NAME;
1167
+ value: Definition['on'];
1168
+ };
1169
+ };
1170
+ [$tada.ref]: makeFragmentRef<Document>;
1171
+ };
1172
+ }
1173
+ : never
1174
+ : never
1175
+ >;
1176
+ type makeFragmentRef<Document> =
1177
+ Document extends FragmentShape<infer Definition, infer Result>
1178
+ ? Definition['masked'] extends false
1179
+ ? Result
1180
+ : {
1181
+ [$tada.fragmentRefs]: {
1182
+ [Name in Definition['fragment']]: Definition['on'];
1183
+ };
1184
+ }
1185
+ : never;
1186
+ type omitFragmentRefsRec<Data> = Data extends readonly (infer Value)[]
1187
+ ? readonly omitFragmentRefsRec<Value>[]
1188
+ : Data extends null
1189
+ ? null
1190
+ : Data extends undefined
1191
+ ? undefined
1192
+ : Data extends {}
1193
+ ? {
1194
+ [Key in Exclude<keyof Data, $tada.fragmentRefs>]: omitFragmentRefsRec<Data[Key]>;
1195
+ }
1196
+ : Data;
1197
+ interface makeUndefinedFragmentRef<FragmentName extends string> {
1198
+ [$tada.fragmentRefs]: {
1199
+ [Name in FragmentName]: 'Undefined Fragment';
1200
+ };
1201
+ }
1202
+ interface DefinitionDecoration<Definition = FragmentDefDecorationLike> {
1203
+ [$tada.definition]?: Definition;
1204
+ }
1205
+ interface FragmentShape<
1206
+ Definition extends FragmentDefDecorationLike = FragmentDefDecorationLike,
1207
+ Result = unknown,
1208
+ > extends DocumentDecoration<Result>,
1209
+ DefinitionDecoration<Definition> {}
1210
+
1211
+ type ObjectLikeType = {
1212
+ kind: 'OBJECT' | 'INTERFACE' | 'UNION';
1213
+ name: string;
1214
+ fields: {
1215
+ [key: string]: any;
1216
+ };
1217
+ };
1218
+ type narrowTypename<T, Typename> = '__typename' extends keyof T
1219
+ ? T extends {
1220
+ __typename?: Typename;
1221
+ }
1222
+ ? T
1223
+ : never
1224
+ : T;
1225
+ type unwrapTypeRec$1<
1226
+ Type,
1227
+ SelectionSet,
1228
+ Introspection extends SchemaLike,
1229
+ Fragments extends {
1230
+ [name: string]: any;
1231
+ },
1232
+ IsOptional,
1233
+ > = Type extends {
1234
+ readonly kind: 'NON_NULL';
1235
+ readonly ofType: any;
1236
+ }
1237
+ ? unwrapTypeRec$1<
1238
+ Type['ofType'],
1239
+ SelectionSet,
1240
+ Introspection,
1241
+ Fragments,
1242
+ IsOptional extends void ? false : IsOptional
1243
+ >
1244
+ : Type extends {
1245
+ readonly kind: 'LIST';
1246
+ readonly ofType: any;
1247
+ }
1248
+ ? IsOptional extends false
1249
+ ? Array<unwrapTypeRec$1<Type['ofType'], SelectionSet, Introspection, Fragments, void>>
1250
+ : null | Array<unwrapTypeRec$1<Type['ofType'], SelectionSet, Introspection, Fragments, void>>
1251
+ : Type extends {
1252
+ readonly name: string;
1253
+ }
1254
+ ? Introspection['types'][Type['name']] extends ObjectLikeType
1255
+ ? SelectionSet extends {
1256
+ kind: Kind.SELECTION_SET;
1257
+ selections: any;
1258
+ }
1259
+ ? IsOptional extends false
1260
+ ? getSelection<
1261
+ SelectionSet['selections'],
1262
+ Introspection['types'][Type['name']],
1263
+ Introspection,
1264
+ Fragments
1265
+ >
1266
+ : null | getSelection<
1267
+ SelectionSet['selections'],
1268
+ Introspection['types'][Type['name']],
1269
+ Introspection,
1270
+ Fragments
1271
+ >
1272
+ : unknown
1273
+ : Introspection['types'][Type['name']] extends {
1274
+ type: any;
1275
+ }
1276
+ ? IsOptional extends false
1277
+ ? Introspection['types'][Type['name']]['type']
1278
+ : Introspection['types'][Type['name']]['type'] | null
1279
+ : IsOptional extends false
1280
+ ? Introspection['types'][Type['name']]['enumValues']
1281
+ : Introspection['types'][Type['name']]['enumValues'] | null
1282
+ : unknown;
1283
+ type getTypeDirective<Node> = Node extends {
1284
+ directives: any[];
1285
+ }
1286
+ ? Node['directives'][number]['name']['value'] & ('required' | '_required') extends never
1287
+ ? Node['directives'][number]['name']['value'] & ('optional' | '_optional') extends never
1288
+ ? void
1289
+ : true
1290
+ : false
1291
+ : void;
1292
+ type isOptional<Node> = Node extends {
1293
+ directives: any[];
1294
+ }
1295
+ ? Node['directives'][number]['name']['value'] & ('include' | 'skip' | 'defer') extends never
1296
+ ? false
1297
+ : true
1298
+ : false;
1299
+ type getFieldAlias<Node> = Node extends {
1300
+ alias: undefined;
1301
+ name: any;
1302
+ }
1303
+ ? Node['name']['value']
1304
+ : Node extends {
1305
+ alias: any;
1306
+ }
1307
+ ? Node['alias']['value']
1308
+ : never;
1309
+ type getFragmentSelection<
1310
+ Node,
1311
+ PossibleType extends string,
1312
+ Type extends ObjectLikeType,
1313
+ Introspection extends SchemaLike,
1314
+ Fragments extends {
1315
+ [name: string]: any;
1316
+ },
1317
+ > = Node extends {
1318
+ kind: Kind.INLINE_FRAGMENT;
1319
+ selectionSet: any;
1320
+ }
1321
+ ? getPossibleTypeSelectionRec<
1322
+ Node['selectionSet']['selections'],
1323
+ PossibleType,
1324
+ Type,
1325
+ Introspection,
1326
+ Fragments
1327
+ >
1328
+ : Node extends {
1329
+ kind: Kind.FRAGMENT_SPREAD;
1330
+ name: any;
1331
+ }
1332
+ ? Node['name']['value'] extends keyof Fragments
1333
+ ? Fragments[Node['name']['value']] extends {
1334
+ [$tada.ref]: any;
1335
+ }
1336
+ ? Type extends {
1337
+ kind: 'INTERFACE';
1338
+ name: any;
1339
+ }
1340
+ ? narrowTypename<Fragments[Node['name']['value']][$tada.ref], PossibleType>
1341
+ : Fragments[Node['name']['value']][$tada.ref]
1342
+ : getPossibleTypeSelectionRec<
1343
+ Fragments[Node['name']['value']]['selectionSet']['selections'],
1344
+ PossibleType,
1345
+ Type,
1346
+ Introspection,
1347
+ Fragments
1348
+ >
1349
+ : never
1350
+ : never;
1351
+ type getSpreadSubtype<
1352
+ Node,
1353
+ BaseType extends ObjectLikeType,
1354
+ Introspection extends SchemaLike,
1355
+ Fragments extends {
1356
+ [name: string]: any;
1357
+ },
1358
+ > = Node extends {
1359
+ kind: Kind.INLINE_FRAGMENT;
1360
+ typeCondition?: any;
1361
+ }
1362
+ ? Node['typeCondition'] extends {
1363
+ kind: Kind.NAMED_TYPE;
1364
+ name: any;
1365
+ }
1366
+ ? Introspection['types'][Node['typeCondition']['name']['value']]
1367
+ : BaseType
1368
+ : Node extends {
1369
+ kind: Kind.FRAGMENT_SPREAD;
1370
+ name: any;
1371
+ }
1372
+ ? Node['name']['value'] extends keyof Fragments
1373
+ ? Introspection['types'][Fragments[Node['name']['value']]['typeCondition']['name']['value']]
1374
+ : void
1375
+ : void;
1376
+ type getTypenameOfType<Type> =
1377
+ | (Type extends {
1378
+ name: any;
1379
+ }
1380
+ ? Type['name']
1381
+ : never)
1382
+ | (Type extends {
1383
+ possibleTypes: any;
1384
+ }
1385
+ ? Type['possibleTypes']
1386
+ : never);
1387
+ type getSelection<
1388
+ Selections,
1389
+ Type extends ObjectLikeType,
1390
+ Introspection extends SchemaLike,
1391
+ Fragments extends {
1392
+ [name: string]: any;
1393
+ },
1394
+ > = Type extends {
1395
+ kind: 'UNION' | 'INTERFACE';
1396
+ possibleTypes: any;
1397
+ }
1398
+ ? {
1399
+ [PossibleType in Type['possibleTypes']]: getPossibleTypeSelectionRec<
1400
+ Selections,
1401
+ PossibleType,
1402
+ Type,
1403
+ Introspection,
1404
+ Fragments,
1405
+ typeSelectionResult<{
1406
+ __typename?: PossibleType;
1407
+ }>
1408
+ >;
1409
+ }[Type['possibleTypes']]
1410
+ : Type extends {
1411
+ kind: 'OBJECT';
1412
+ name: any;
1413
+ }
1414
+ ? getPossibleTypeSelectionRec<Selections, Type['name'], Type, Introspection, Fragments>
1415
+ : {};
1416
+ interface typeSelectionResult<Fields extends {} = {}, Rest = unknown> {
1417
+ fields: Fields;
1418
+ rest: Rest;
1419
+ }
1420
+ type getPossibleTypeSelectionRec<
1421
+ Selections,
1422
+ PossibleType extends string,
1423
+ Type extends ObjectLikeType,
1424
+ Introspection extends SchemaLike,
1425
+ Fragments extends {
1426
+ [name: string]: any;
1427
+ },
1428
+ SelectionAcc extends typeSelectionResult = typeSelectionResult,
1429
+ > = Selections extends [infer Node, ...infer Rest]
1430
+ ? getPossibleTypeSelectionRec<
1431
+ Rest,
1432
+ PossibleType,
1433
+ Type,
1434
+ Introspection,
1435
+ Fragments,
1436
+ Node extends {
1437
+ kind: Kind.FRAGMENT_SPREAD | Kind.INLINE_FRAGMENT;
1438
+ }
1439
+ ? getSpreadSubtype<Node, Type, Introspection, Fragments> extends infer Subtype extends
1440
+ ObjectLikeType
1441
+ ? PossibleType extends getTypenameOfType<Subtype>
1442
+ ? isOptional<Node> extends true
1443
+ ? typeSelectionResult<
1444
+ SelectionAcc['fields'],
1445
+ SelectionAcc['rest'] &
1446
+ (
1447
+ | {}
1448
+ | getFragmentSelection<Node, PossibleType, Subtype, Introspection, Fragments>
1449
+ )
1450
+ >
1451
+ : typeSelectionResult<
1452
+ SelectionAcc['fields'] &
1453
+ getFragmentSelection<Node, PossibleType, Subtype, Introspection, Fragments>,
1454
+ SelectionAcc['rest']
1455
+ >
1456
+ : SelectionAcc
1457
+ : Node extends {
1458
+ kind: Kind.FRAGMENT_SPREAD;
1459
+ name: any;
1460
+ }
1461
+ ? typeSelectionResult<
1462
+ SelectionAcc['fields'] & makeUndefinedFragmentRef<Node['name']['value']>,
1463
+ SelectionAcc['rest']
1464
+ >
1465
+ : SelectionAcc
1466
+ : Node extends {
1467
+ kind: Kind.FIELD;
1468
+ name: any;
1469
+ selectionSet: any;
1470
+ }
1471
+ ? isOptional<Node> extends true
1472
+ ? typeSelectionResult<
1473
+ SelectionAcc['fields'] & {
1474
+ [Prop in getFieldAlias<Node>]?: Node['name']['value'] extends '__typename'
1475
+ ? PossibleType
1476
+ : unwrapTypeRec$1<
1477
+ Type['fields'][Node['name']['value']]['type'],
1478
+ Node['selectionSet'],
1479
+ Introspection,
1480
+ Fragments,
1481
+ getTypeDirective<Node>
1482
+ >;
1483
+ },
1484
+ SelectionAcc['rest']
1485
+ >
1486
+ : typeSelectionResult<
1487
+ SelectionAcc['fields'] & {
1488
+ [Prop in getFieldAlias<Node>]: Node['name']['value'] extends '__typename'
1489
+ ? PossibleType
1490
+ : unwrapTypeRec$1<
1491
+ Type['fields'][Node['name']['value']]['type'],
1492
+ Node['selectionSet'],
1493
+ Introspection,
1494
+ Fragments,
1495
+ getTypeDirective<Node>
1496
+ >;
1497
+ },
1498
+ SelectionAcc['rest']
1499
+ >
1500
+ : SelectionAcc
1501
+ >
1502
+ : SelectionAcc['rest'] extends infer T
1503
+ ? obj<SelectionAcc['fields'] & T>
1504
+ : never;
1505
+ type getOperationSelectionType<
1506
+ Definition,
1507
+ Introspection extends SchemaLike,
1508
+ Fragments extends {
1509
+ [name: string]: any;
1510
+ },
1511
+ > = Definition extends {
1512
+ kind: Kind.OPERATION_DEFINITION;
1513
+ selectionSet: any;
1514
+ operation: any;
1515
+ }
1516
+ ? Introspection['types'][Introspection[Definition['operation']]] extends infer Type extends
1517
+ ObjectLikeType
1518
+ ? getSelection<Definition['selectionSet']['selections'], Type, Introspection, Fragments>
1519
+ : {}
1520
+ : never;
1521
+ type getFragmentSelectionType<
1522
+ Definition,
1523
+ Introspection extends SchemaLike,
1524
+ Fragments extends {
1525
+ [name: string]: any;
1526
+ },
1527
+ > = Definition extends {
1528
+ kind: Kind.FRAGMENT_DEFINITION;
1529
+ selectionSet: any;
1530
+ typeCondition: any;
1531
+ }
1532
+ ? Introspection['types'][Definition['typeCondition']['name']['value']] extends infer Type extends
1533
+ ObjectLikeType
1534
+ ? getSelection<Definition['selectionSet']['selections'], Type, Introspection, Fragments>
1535
+ : never
1536
+ : never;
1537
+ type getDocumentType<
1538
+ Document extends DocumentNodeLike,
1539
+ Introspection extends SchemaLike,
1540
+ Fragments extends {
1541
+ [name: string]: any;
1542
+ } = {},
1543
+ > = Document['definitions'] extends readonly [infer Definition, ...infer Rest]
1544
+ ? Definition extends {
1545
+ kind: Kind.OPERATION_DEFINITION;
1546
+ }
1547
+ ? getOperationSelectionType<Definition, Introspection, getFragmentMapRec<Rest> & Fragments>
1548
+ : Definition extends {
1549
+ kind: Kind.FRAGMENT_DEFINITION;
1550
+ }
1551
+ ? getFragmentSelectionType<Definition, Introspection, getFragmentMapRec<Rest> & Fragments>
1552
+ : never
1553
+ : never;
1554
+ type getFragmentMapRec<Definitions, FragmentMap = {}> = Definitions extends readonly [
1555
+ infer Definition,
1556
+ ...infer Rest,
1557
+ ]
1558
+ ? getFragmentMapRec<
1559
+ Rest,
1560
+ Definition extends {
1561
+ kind: Kind.FRAGMENT_DEFINITION;
1562
+ name: any;
1563
+ }
1564
+ ? {
1565
+ [Name in Definition['name']['value']]: Definition;
1566
+ } & FragmentMap
1567
+ : FragmentMap
1568
+ >
1569
+ : FragmentMap;
1570
+
1571
+ type getInputObjectTypeRec<
1572
+ InputFields,
1573
+ Introspection extends SchemaLike,
1574
+ InputObject = {},
1575
+ > = InputFields extends [infer InputField, ...infer Rest]
1576
+ ? getInputObjectTypeRec<
1577
+ Rest,
1578
+ Introspection,
1579
+ (InputField extends {
1580
+ name: any;
1581
+ type: any;
1582
+ }
1583
+ ? InputField extends {
1584
+ defaultValue?: undefined | null;
1585
+ type: {
1586
+ kind: 'NON_NULL';
1587
+ };
1588
+ }
1589
+ ? {
1590
+ [Name in InputField['name']]: unwrapTypeRec<InputField['type'], Introspection, true>;
1591
+ }
1592
+ : {
1593
+ [Name in InputField['name']]?: unwrapTypeRec<
1594
+ InputField['type'],
1595
+ Introspection,
1596
+ true
1597
+ > | null;
1598
+ }
1599
+ : {}) &
1600
+ InputObject
1601
+ >
1602
+ : obj<InputObject>;
1603
+ type getInputObjectTypeOneOfRec<
1604
+ InputFields,
1605
+ Introspection extends SchemaLike,
1606
+ InputObject = never,
1607
+ > = InputFields extends [infer InputField, ...infer Rest]
1608
+ ? getInputObjectTypeOneOfRec<
1609
+ Rest,
1610
+ Introspection,
1611
+ | (InputField extends {
1612
+ name: any;
1613
+ type: any;
1614
+ }
1615
+ ? {
1616
+ [Name in InputField['name']]: unwrapTypeRec<InputField['type'], Introspection, false>;
1617
+ }
1618
+ : never)
1619
+ | InputObject
1620
+ >
1621
+ : InputObject;
1622
+ type unwrapTypeRec<TypeRef, Introspection extends SchemaLike, IsOptional> = TypeRef extends {
1623
+ kind: 'NON_NULL';
1624
+ ofType: any;
1625
+ }
1626
+ ? unwrapTypeRec<TypeRef['ofType'], Introspection, false>
1627
+ : TypeRef extends {
1628
+ kind: 'LIST';
1629
+ ofType: any;
1630
+ }
1631
+ ? IsOptional extends false
1632
+ ? Array<unwrapTypeRec<TypeRef['ofType'], Introspection, true>>
1633
+ : null | Array<unwrapTypeRec<TypeRef['ofType'], Introspection, true>>
1634
+ : TypeRef extends {
1635
+ name: any;
1636
+ }
1637
+ ? IsOptional extends false
1638
+ ? getScalarType<TypeRef['name'], Introspection>
1639
+ : null | getScalarType<TypeRef['name'], Introspection>
1640
+ : unknown;
1641
+ type unwrapTypeRefRec<Type, Introspection extends SchemaLike, IsOptional> = Type extends {
1642
+ kind: Kind.NON_NULL_TYPE;
1643
+ type: any;
1644
+ }
1645
+ ? unwrapTypeRefRec<Type['type'], Introspection, false>
1646
+ : Type extends {
1647
+ kind: Kind.LIST_TYPE;
1648
+ type: any;
1649
+ }
1650
+ ? IsOptional extends false
1651
+ ? Array<unwrapTypeRefRec<Type['type'], Introspection, true>>
1652
+ : null | Array<unwrapTypeRefRec<Type['type'], Introspection, true>>
1653
+ : Type extends {
1654
+ kind: Kind.NAMED_TYPE;
1655
+ name: any;
1656
+ }
1657
+ ? IsOptional extends false
1658
+ ? getScalarType<Type['name']['value'], Introspection>
1659
+ : null | getScalarType<Type['name']['value'], Introspection>
1660
+ : unknown;
1661
+ type _getVariablesRec<
1662
+ Variables,
1663
+ Introspection extends SchemaLike,
1664
+ VariablesObject = {},
1665
+ > = Variables extends [infer Variable, ...infer Rest]
1666
+ ? _getVariablesRec<
1667
+ Rest,
1668
+ Introspection,
1669
+ (Variable extends {
1670
+ kind: Kind.VARIABLE_DEFINITION;
1671
+ variable: any;
1672
+ type: any;
1673
+ }
1674
+ ? Variable extends {
1675
+ defaultValue: undefined;
1676
+ type: {
1677
+ kind: Kind.NON_NULL_TYPE;
1678
+ };
1679
+ }
1680
+ ? {
1681
+ [Name in Variable['variable']['name']['value']]: unwrapTypeRefRec<
1682
+ Variable['type'],
1683
+ Introspection,
1684
+ true
1685
+ >;
1686
+ }
1687
+ : {
1688
+ [Name in Variable['variable']['name']['value']]?: unwrapTypeRefRec<
1689
+ Variable['type'],
1690
+ Introspection,
1691
+ true
1692
+ >;
1693
+ }
1694
+ : {}) &
1695
+ VariablesObject
1696
+ >
1697
+ : obj<VariablesObject>;
1698
+ type getVariablesType<
1699
+ Document extends DocumentNodeLike,
1700
+ Introspection extends SchemaLike,
1701
+ > = _getVariablesRec<Document['definitions'][0]['variableDefinitions'], Introspection>;
1702
+ type getScalarType<
1703
+ TypeName,
1704
+ Introspection extends SchemaLike,
1705
+ > = TypeName extends keyof Introspection['types']
1706
+ ? Introspection['types'][TypeName] extends {
1707
+ kind: 'INPUT_OBJECT';
1708
+ inputFields: any;
1709
+ isOneOf?: any;
1710
+ }
1711
+ ? Introspection['types'][TypeName]['isOneOf'] extends true
1712
+ ? getInputObjectTypeOneOfRec<Introspection['types'][TypeName]['inputFields'], Introspection>
1713
+ : getInputObjectTypeRec<Introspection['types'][TypeName]['inputFields'], Introspection>
1714
+ : Introspection['types'][TypeName] extends {
1715
+ type: any;
1716
+ }
1717
+ ? Introspection['types'][TypeName]['type']
1718
+ : Introspection['types'][TypeName]['enumValues']
1719
+ : never;
1720
+
1721
+ type fragmentRegistryEntry<Fragment> =
1722
+ Fragment extends FragmentShape<infer Definition, infer Result>
1723
+ ? {
1724
+ [Name in Definition['fragment']]: Result;
1725
+ }
1726
+ : never;
1727
+ type fragmentRegistry<Fragments extends readonly FragmentShape[]> = overload<
1728
+ fragmentRegistryEntry<Fragments[number]> | {}
1729
+ >;
1730
+ type unmaskFragmentSpreadsRec<Refs, Registry> = overload<
1731
+ keyof Refs extends infer Name
1732
+ ? Name extends keyof Registry
1733
+ ? unmaskFragmentRefsRec<Registry[Name], Registry>
1734
+ : Name extends keyof Refs
1735
+ ? {
1736
+ [$tada.fragmentRefs]: {
1737
+ [N in Name]: Refs[N];
1738
+ };
1739
+ }
1740
+ : never
1741
+ : never
1742
+ >;
1743
+ type unmaskFragmentRefsRec<Data, Registry> = Data extends readonly (infer Value)[]
1744
+ ? readonly unmaskFragmentRefsRec<Value, Registry>[]
1745
+ : Data extends null
1746
+ ? null
1747
+ : Data extends undefined
1748
+ ? undefined
1749
+ : Data extends {
1750
+ [$tada.fragmentRefs]: infer Refs;
1751
+ }
1752
+ ? obj<
1753
+ {
1754
+ [Key in Exclude<keyof Data, $tada.fragmentRefs>]: unmaskFragmentRefsRec<
1755
+ Data[Key],
1756
+ Registry
1757
+ >;
1758
+ } & unmaskFragmentSpreadsRec<Refs, Registry>
1759
+ >
1760
+ : Data extends object
1761
+ ? {
1762
+ [Key in keyof Data]: unmaskFragmentRefsRec<Data[Key], Registry>;
1763
+ }
1764
+ : Data;
1765
+ /** For testing, converts document data to its result type, resolving nested fragments.
1766
+ *
1767
+ * @param _document - A GraphQL document, created using `graphql`.
1768
+ * @param data - The result data of the document, with fragment data inlined.
1769
+ * @param _fragments - A list of every fragment used in the document, transitively.
1770
+ * @returns The result data, cast to the result type of the document.
1771
+ *
1772
+ * @remarks
1773
+ * When a document spreads fragments, its result type only contains opaque
1774
+ * references to them, rather than the fragments’ fields, which makes it hard to
1775
+ * write a fixture for the full result.
1776
+ *
1777
+ * Unlike `unsafe_readResult`, which discards all fragment references and checks
1778
+ * nothing nested inside them, `readResult` accepts the document’s fragments and
1779
+ * recursively resolves their references, so your data is fully type-checked —
1780
+ * including fragments that spread other fragments.
1781
+ *
1782
+ * Any fragment you leave out of the `fragments` argument stays masked, so a
1783
+ * missing fragment surfaces as a still-masked reference rather than inlined data,
1784
+ * and can be filled with `maskFragments` instead.
1785
+ *
1786
+ * Intended for tests, storybooks, fixtures, and cache updaters.
1787
+ *
1788
+ * @example
1789
+ * ```
1790
+ * import { graphql } from 'gql.tada';
1791
+ * import { readResult } from 'gql.tada/testing';
1792
+ *
1793
+ * const authorFragment = graphql(`
1794
+ * fragment AuthorFields on Author {
1795
+ * name
1796
+ * }
1797
+ * `);
1798
+ *
1799
+ * const todoFragment = graphql(`
1800
+ * fragment TodoFields on Todo {
1801
+ * id
1802
+ * author {
1803
+ * ...AuthorFields
1804
+ * }
1805
+ * }
1806
+ * `, [authorFragment]);
1807
+ *
1808
+ * const query = graphql(`
1809
+ * query {
1810
+ * todos {
1811
+ * id
1812
+ * ...TodoFields
1813
+ * }
1814
+ * }
1815
+ * `, [todoFragment]);
1816
+ *
1817
+ * const data = readResult(
1818
+ * query,
1819
+ * { todos: [{ id: 'id', author: { name: 'name' } }] },
1820
+ * [todoFragment, authorFragment]
1821
+ * );
1822
+ * ```
1823
+ *
1824
+ * @see {@link maskFragments} for masking a single level of fragment data.
1825
+ * @see {@link unsafe_readResult} for the unsafe variant that performs no checks.
1826
+ */
1827
+ declare function readResult<
1828
+ const Document extends DocumentDecoration<any, any>,
1829
+ const Fragments extends readonly FragmentShape[],
1830
+ >(
1831
+ document: Document,
1832
+ data: unmaskFragmentRefsRec<ResultOf<Document>, fragmentRegistry<Fragments>>,
1833
+ fragments: Fragments
1834
+ ): ResultOf<Document>;
1835
+ type resultOfFragmentsRec<
1836
+ Fragments extends readonly any[],
1837
+ Result = {},
1838
+ > = Fragments extends readonly [infer Fragment, ...infer Rest]
1839
+ ? resultOfFragmentsRec<Rest, ResultOf<Fragment> & Result>
1840
+ : Result;
1841
+ type fragmentRefsOfFragmentsRec<
1842
+ Fragments extends readonly any[],
1843
+ FragmentRefs = {},
1844
+ > = Fragments extends readonly [infer Fragment, ...infer Rest]
1845
+ ? fragmentRefsOfFragmentsRec<Rest, makeFragmentRef<Fragment> & FragmentRefs>
1846
+ : obj<FragmentRefs>;
1847
+ /** For testing, masks fragment data for given data and fragments.
1848
+ *
1849
+ * @param _fragments - A list of GraphQL documents of fragments, created using `graphql`.
1850
+ * @param data - The combined result data of the fragments, which can be wrapped in arrays.
1851
+ * @returns The masked data of the fragments.
1852
+ *
1853
+ * @remarks
1854
+ * When creating test data, you may define data for fragments that’s unmasked, making it
1855
+ * unusable in parent fragments or queries that require masked data.
1856
+ *
1857
+ * This means that you may have to use {@link maskFragments} to mask your data first
1858
+ * for TypeScript to not report an error.
1859
+ *
1860
+ * @example
1861
+ * ```
1862
+ * import { FragmentOf, ResultOf, graphql } from 'gql.tada';
1863
+ * import { maskFragments } from 'gql.tada/testing';
1864
+ *
1865
+ * const bookFragment = graphql(`
1866
+ * fragment BookComponent on Book {
1867
+ * id
1868
+ * title
1869
+ * }
1870
+ * `);
1871
+ *
1872
+ * const data = maskFragments([bookFragment], { id: 'id', title: 'book' });
1873
+ * ```
1874
+ *
1875
+ * @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)
1876
+ */
1877
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1878
+ _fragments: Fragments,
1879
+ fragment: resultOfFragmentsRec<Fragments>
1880
+ ): fragmentRefsOfFragmentsRec<Fragments>;
1881
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1882
+ _fragments: Fragments,
1883
+ fragment: resultOfFragmentsRec<Fragments> | null
1884
+ ): fragmentRefsOfFragmentsRec<Fragments> | null;
1885
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1886
+ _fragments: Fragments,
1887
+ fragment: resultOfFragmentsRec<Fragments> | undefined
1888
+ ): fragmentRefsOfFragmentsRec<Fragments> | undefined;
1889
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1890
+ _fragments: Fragments,
1891
+ fragment: resultOfFragmentsRec<Fragments> | null | undefined
1892
+ ): fragmentRefsOfFragmentsRec<Fragments> | null | undefined;
1893
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1894
+ _fragments: Fragments,
1895
+ fragment: readonly resultOfFragmentsRec<Fragments>[]
1896
+ ): readonly fragmentRefsOfFragmentsRec<Fragments>[];
1897
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1898
+ _fragments: Fragments,
1899
+ fragment: readonly (resultOfFragmentsRec<Fragments> | null)[]
1900
+ ): readonly (fragmentRefsOfFragmentsRec<Fragments> | null)[];
1901
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1902
+ _fragments: Fragments,
1903
+ fragment: readonly (resultOfFragmentsRec<Fragments> | undefined)[]
1904
+ ): readonly (fragmentRefsOfFragmentsRec<Fragments> | undefined)[];
1905
+ declare function maskFragments<const Fragments extends readonly FragmentShape[]>(
1906
+ _fragments: Fragments,
1907
+ fragment: readonly (resultOfFragmentsRec<Fragments> | null | undefined)[]
1908
+ ): readonly (fragmentRefsOfFragmentsRec<Fragments> | null | undefined)[];
1909
+ /** For testing, converts document data without fragment refs to their result type.
1910
+ *
1911
+ * @param _document - A GraphQL document, created using `graphql`.
1912
+ * @param data - The result data of the GraphQL document with optional fragment refs.
1913
+ * @returns The masked result data of the document.
1914
+ *
1915
+ * @remarks
1916
+ * When creating test data, you may define data for documents that’s unmasked, but
1917
+ * need to cast the data to match the result type of your document.
1918
+ *
1919
+ * This means that you may have to use {@link unsafe_readResult} to cast
1920
+ * them to the result type, instead of doing `as any as ResultOf<typeof document>`.
1921
+ *
1922
+ * This function is inherently unsafe, since it doesn't check that your document
1923
+ * actually contains the masked fragment data! For a type-safe alternative that
1924
+ * resolves nested fragments, see {@link readResult}.
1925
+ *
1926
+ * @example
1927
+ * ```
1928
+ * import { FragmentOf, ResultOf, graphql } from 'gql.tada';
1929
+ * import { unsafe_readResult } from 'gql.tada/testing';
1930
+ *
1931
+ * const bookFragment = graphql(`
1932
+ * fragment BookComponent on Book {
1933
+ * id
1934
+ * title
1935
+ * }
1936
+ * `);
1937
+ *
1938
+ * const query = graphql(`
1939
+ * query {
1940
+ * book {
1941
+ * ...BookComponent
1942
+ * }
1943
+ * }
1944
+ * `, [bookFragment]);
1945
+ *
1946
+ * const data = unsafe_readResult(query, { book: { id: 'id', title: 'book' } });
1947
+ * ```
1948
+ *
1949
+ * @see {@link readResult} for a type-safe alternative that resolves nested fragments.
1950
+ * @see {@link readFragment} for how to read from fragment masks (i.e. the reverse)
1951
+ */
1952
+ declare function unsafe_readResult<
1953
+ const Document extends DocumentDecoration<any, any>,
1954
+ const Data extends omitFragmentRefsRec<ResultOf<Document>>,
1955
+ >(_document: Document, data: Data): ResultOf<Document>;
1956
+
1957
+ /** Abstract configuration type input for your schema and scalars.
1958
+ *
1959
+ * @remarks
1960
+ * This is used either via {@link setupSchema} or {@link initGraphQLTada} to set
1961
+ * up your schema and scalars.
1962
+ *
1963
+ * The `scalars` option is optional and can be used to set up more scalars, apart
1964
+ * from the default ones (like: Int, Float, String, Boolean).
1965
+ * It must be an object map of scalar names to their desired TypeScript types.
1966
+ *
1967
+ * @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.
1968
+ * @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.
1969
+ */
1970
+ interface AbstractSetupSchema {
1971
+ introspection: IntrospectionLikeInput;
1972
+ scalars?: ScalarsLike;
1973
+ disableMasking?: boolean;
1974
+ }
1975
+ /** Abstract type for internal configuration
1976
+ * @internal
1977
+ */
1978
+ interface AbstractConfig {
1979
+ isMaskingDisabled: boolean;
1980
+ }
1981
+ /** This is used to configure gql.tada with your introspection data and scalars.
1982
+ *
1983
+ * @remarks
1984
+ * You may extend this interface via declaration merging with your {@link IntrospectionQuery}
1985
+ * data and optionally your scalars to get proper type inference.
1986
+ * This is done by declaring a declaration for it as per the following example.
1987
+ *
1988
+ * Configuring scalars is optional and by default the standard scalrs are already
1989
+ * defined.
1990
+ *
1991
+ * This will configure the {@link graphql} export to infer types from your schema.
1992
+ * Alternatively, you may call {@link initGraphQLTada} instead.
1993
+ *
1994
+ * @param introspection - Introspection of your schema matching {@link IntrospectionQuery}.
1995
+ * @param scalars - An object type with scalar names as keys and the corresponding scalar types as values.
1996
+ *
1997
+ * @example
1998
+ * ```
1999
+ * import type { myIntrospection } from './myIntrospection';
2000
+ *
2001
+ * declare module 'gql.tada' {
2002
+ * interface setupSchema {
2003
+ * introspection: typeof myIntrospection;
2004
+ * scalars: {
2005
+ * DateTime: string;
2006
+ * Json: any;
2007
+ * };
2008
+ * }
2009
+ * }
2010
+ * ```
2011
+ */
2012
+ interface setupSchema extends AbstractSetupSchema {}
2013
+ interface AbstractSetupCache {
2014
+ readonly __cacheDisabled: unknown;
2015
+ }
2016
+ interface setupCache extends AbstractSetupCache {}
2017
+ interface GraphQLTadaAPI<Schema extends SchemaLike, Config extends AbstractConfig> {
2018
+ /** In "multi-schema" mode this identifies the schema.
2019
+ * @internal */
2020
+ readonly __name: Schema['name'];
2021
+ /** Function to create and compose GraphQL documents with result and variable types.
2022
+ *
2023
+ * @param input - A string of a GraphQL document.
2024
+ * @param fragments - An optional list of other GraphQL fragments created with this function.
2025
+ * @returns A {@link DocumentNode} with result and variables types.
2026
+ *
2027
+ * @remarks
2028
+ * This function creates a {@link DocumentNode} with result and variables types.
2029
+ * It is used with your schema in {@link setupSchema} to create a result type
2030
+ * of your queries, fragments, and variables.
2031
+ *
2032
+ * You can compose fragments into this function by passing them and a fragment
2033
+ * mask will be created for them.
2034
+ * When creating queries, the returned document of queries can be passed into GraphQL clients
2035
+ * which will then automatically infer the result and variables types.
2036
+ *
2037
+ * @example
2038
+ * ```
2039
+ * import { graphql } from 'gql.tada';
2040
+ *
2041
+ * const bookFragment = graphql(`
2042
+ * fragment BookComponent on Book {
2043
+ * id
2044
+ * title
2045
+ * }
2046
+ * `);
2047
+ *
2048
+ * const bookQuery = graphql(`
2049
+ * query Book ($id: ID!) {
2050
+ * book(id: $id) {
2051
+ * id
2052
+ * ...BookComponent
2053
+ * }
2054
+ * }
2055
+ * `, [bookFragment]);
2056
+ * ```
2057
+ *
2058
+ * @see {@link readFragment} for how to read from fragment masks.
2059
+ */
2060
+ <
2061
+ const In extends unknown extends setupCache['__cacheDisabled'] ? keyof setupCache : never,
2062
+ const Fragments extends readonly FragmentShape[],
2063
+ >(
2064
+ input: In,
2065
+ fragments?: Fragments
2066
+ ): setupCache[In];
2067
+ <const In extends string, const Fragments extends readonly FragmentShape[]>(
2068
+ input: In,
2069
+ fragments?: Fragments
2070
+ ): getDocumentNode<
2071
+ parseDocument<In>,
2072
+ Schema,
2073
+ getFragmentsOfDocuments<Fragments>,
2074
+ Config['isMaskingDisabled']
2075
+ >;
2076
+ /** Function to validate the type of a given scalar or enum value.
2077
+ *
2078
+ * @param name - The name of a scalar or enum type.
2079
+ * @param value - An optional scalar value of the given type.
2080
+ * @returns A {@link DocumentNode} with result and variables types.
2081
+ *
2082
+ * @remarks
2083
+ * This function validates that a value matches an enum or scalar type
2084
+ * as a type check.
2085
+ *
2086
+ * You can use it to retrieve the type of a given scalar or enum type
2087
+ * for use in a utility function or separate component that only
2088
+ * accepts a primitive scalar or enum value.
2089
+ *
2090
+ * Note that this function does not perform runtime checks of your
2091
+ * scalar value!
2092
+ *
2093
+ * @example
2094
+ * ```
2095
+ * import { graphql } from 'gql.tada';
2096
+ *
2097
+ * type myEnum = ReturnType<graphql.scalar<'myEnum'>>;
2098
+ *
2099
+ * const myEnumValue = graphql.scalar('myEnum', 'value');
2100
+ * ```
2101
+ */
2102
+ scalar<const Name extends string, Value>(
2103
+ name: Name,
2104
+ value: getScalarType<Name, Schema> extends Value
2105
+ ? Value & getScalarType<Name, Schema>
2106
+ : getScalarType<Name, Schema>
2107
+ ): Value;
2108
+ scalar<const Name extends string, Value>(
2109
+ name: Name,
2110
+ value: getScalarType<Name, Schema> extends Value
2111
+ ? never extends Value
2112
+ ? never
2113
+ : (Value & getScalarType<Name, Schema>) | null
2114
+ : getScalarType<Name, Schema> | null
2115
+ ): Value | null;
2116
+ scalar<const Name extends string, Value>(
2117
+ name: Name,
2118
+ value: getScalarType<Name, Schema> extends Value
2119
+ ? never extends Value
2120
+ ? never
2121
+ : (Value & getScalarType<Name, Schema>) | undefined
2122
+ : getScalarType<Name, Schema> | undefined
2123
+ ): Value | undefined;
2124
+ scalar<const Name extends string, Value>(
2125
+ name: Name,
2126
+ value: getScalarType<Name, Schema> extends Value
2127
+ ? never extends Value
2128
+ ? never
2129
+ : (Value & getScalarType<Name, Schema>) | null | undefined
2130
+ : getScalarType<Name, Schema> | null | undefined
2131
+ ): Value | null | undefined;
2132
+ scalar<const Name extends string>(
2133
+ name: Name,
2134
+ value: getScalarType<Name, Schema> | undefined
2135
+ ): getScalarType<Name, Schema>;
2136
+ /** Function to replace a GraphQL document with a persisted document.
2137
+ *
2138
+ * @typeParam Document - The document type of {@link TadaDocumentNode}.
2139
+ * @param id - A document ID that replaces the document for the API.
2140
+ * @returns A {@link TadaPersistedDocumentNode}.
2141
+ *
2142
+ * @remarks
2143
+ * This function may be used to replace a GraphQL document with a
2144
+ * stand-in, persisted document.
2145
+ *
2146
+ * The returned document’s value won’t contain any of the document’s
2147
+ * definitions, but its type will be equivalent to the `Document` that’s
2148
+ * been passed as a generic.
2149
+ *
2150
+ * As long as the query (type parameter of `Document`) is only referenced
2151
+ * as a type in your code, it will be omitted from your output build by
2152
+ * your bundler and the resulting GraphQL document’s ID will replace your
2153
+ * document entirely.
2154
+ *
2155
+ * @example
2156
+ * ```
2157
+ * import { graphql } from 'gql.tada';
2158
+ *
2159
+ * const query = graphql(`query MyQuery { __typename }`);
2160
+ * const persisted = graphql.persisted<typeof query>('MyQuery');
2161
+ * ```
2162
+ */
2163
+ persisted<Document extends DocumentNodeLike = never>(
2164
+ documentId: string,
2165
+ document?: Document
2166
+ ): Document extends DocumentDecoration<infer Result, infer Variables>
2167
+ ? TadaPersistedDocumentNode<Result, Variables>
2168
+ : never;
2169
+ }
2170
+ type schemaOfSetup<Setup extends AbstractSetupSchema> = addIntrospectionScalars<
2171
+ mapIntrospection<matchOr<IntrospectionLikeInput, Setup['introspection'], never>>,
2172
+ matchOr<ScalarsLike, Setup['scalars'], {}>
2173
+ >;
2174
+ type configOfSetup<Setup extends AbstractSetupSchema> = {
2175
+ isMaskingDisabled: Setup['disableMasking'] extends true ? true : false;
2176
+ };
2177
+ /** Utility to type-instantiate a `graphql` document function with.
2178
+ *
2179
+ * @remarks
2180
+ * The `initGraphQLTada` type may be used to manually instantiate a type
2181
+ * as returned by `initGraphQLTada<>()` with the same input type.
2182
+ *
2183
+ * @example
2184
+ * ```
2185
+ * import { initGraphQLTada } from 'gql.tada';
2186
+ * import type { myIntrospection } from './myIntrospection';
2187
+ *
2188
+ * export const graphql: initGraphQLTada<{
2189
+ * introspection: typeof myIntrospection;
2190
+ * scalars: {
2191
+ * DateTime: string;
2192
+ * Json: any;
2193
+ * };
2194
+ * }> = initGraphQLTada();
2195
+ *
2196
+ * const query = graphql(`{ __typename }`);
2197
+ * ```
2198
+ */
2199
+ type initGraphQLTada<Setup extends AbstractSetupSchema> = GraphQLTadaAPI<
2200
+ schemaOfSetup<Setup>,
2201
+ configOfSetup<Setup>
2202
+ >;
2203
+ /** Setup function to create a typed `graphql` document function with.
2204
+ *
2205
+ * @remarks
2206
+ * `initGraphQLTada` accepts an {@link AbstractSetupSchema} configuration object as a generic
2207
+ * and returns a `graphql` function that may be used to create documents typed using your
2208
+ * GraphQL schema.
2209
+ *
2210
+ * You should use and re-export the resulting function named as `graphql` or `gql` for your
2211
+ * editor and the TypeScript language server to recognize your GraphQL documents correctly.
2212
+ *
2213
+ * @example
2214
+ * ```
2215
+ * import { initGraphQLTada } from 'gql.tada';
2216
+ * import type { myIntrospection } from './myIntrospection';
2217
+ *
2218
+ * export const graphql = initGraphQLTada<{
2219
+ * introspection: typeof myIntrospection;
2220
+ * scalars: {
2221
+ * DateTime: string;
2222
+ * Json: any;
2223
+ * };
2224
+ * }>();
2225
+ *
2226
+ * const query = graphql(`{ __typename }`);
2227
+ * ```
2228
+ */
2229
+ declare function initGraphQLTada<const Setup extends AbstractSetupSchema>(): initGraphQLTada<Setup>;
2230
+ /** Alias to a GraphQL parse function returning an exact document type.
2231
+ *
2232
+ * @param input - A string of a GraphQL document
2233
+ * @returns A parsed {@link DocumentNode}.
2234
+ *
2235
+ * @remarks
2236
+ * This function accepts a GraphQL document string and parses it, just like
2237
+ * GraphQL’s `parse` function. However, its return type will be the exact
2238
+ * structure of the AST parsed in types.
2239
+ */
2240
+ declare function parse<const In extends string>(input: In): parseDocument<In>;
2241
+ type getDocumentNode<
2242
+ Document extends DocumentNodeLike,
2243
+ Introspection extends SchemaLike,
2244
+ Fragments extends {
2245
+ [name: string]: any;
2246
+ } = {},
2247
+ isMaskingDisabled = false,
2248
+ > =
2249
+ getDocumentType<Document, Introspection, Fragments> extends never
2250
+ ? never
2251
+ : TadaDocumentNode<
2252
+ getDocumentType<Document, Introspection, Fragments>,
2253
+ getVariablesType<Document, Introspection>,
2254
+ decorateFragmentDef<Document, isMaskingDisabled>
2255
+ >;
2256
+ /** A GraphQL `DocumentNode` with attached types for results and variables.
2257
+ *
2258
+ * @remarks
2259
+ * This is a GraphQL {@link DocumentNode} with attached types for results and variables.
2260
+ * This is used by GraphQL clients to infer the types of results and variables and provide
2261
+ * type-safety in GraphQL documents.
2262
+ *
2263
+ * You can create typed GraphQL documents using the {@link graphql} function.
2264
+ *
2265
+ * `Result` is the type of GraphQL results, as returned by GraphQL APIs for a given query.
2266
+ * `Variables` is the type of variables, as accepted by GraphQL APIs for a given query.
2267
+ *
2268
+ * @see {@link https://github.com/dotansimha/graphql-typed-document-node} for more information.
2269
+ */
2270
+ interface TadaDocumentNode<
2271
+ Result = {
2272
+ [key: string]: any;
2273
+ },
2274
+ Variables = {
2275
+ [key: string]: any;
2276
+ },
2277
+ Decoration = void,
2278
+ > extends DocumentNode,
2279
+ DocumentDecoration<Result, Variables>,
2280
+ DefinitionDecoration<Decoration> {}
2281
+ /** A GraphQL persisted document with attached types for results and variables.
2282
+ *
2283
+ * @remarks
2284
+ * This type still matches a GraphQL {@link DocumentNode}, but doesn’t contain
2285
+ * any definitions. At runtime, this means that this document is empty.
2286
+ *
2287
+ * Instead of its definitions, it carries an `id` property that is typically
2288
+ * used to uniquely identify the document to your GraphQL API, without disclosing
2289
+ * the shape of the query or schema transparently.
2290
+ */
2291
+ interface TadaPersistedDocumentNode<
2292
+ Result = {
2293
+ [key: string]: any;
2294
+ },
2295
+ Variables = {
2296
+ [key: string]: any;
2297
+ },
2298
+ > extends DocumentNode,
2299
+ DocumentDecoration<Result, Variables> {
2300
+ definitions: readonly DefinitionNode[];
2301
+ documentId: string;
2302
+ }
2303
+ /** A utility type returning the `Result` type of typed GraphQL documents.
2304
+ *
2305
+ * @remarks
2306
+ * This accepts a {@link TadaDocumentNode} and returns the attached `Result` type
2307
+ * of GraphQL documents.
2308
+ */
2309
+ type ResultOf<Document> = Document extends DocumentDecoration<infer Result, any> ? Result : never;
2310
+ /** A utility type returning the `Variables` type of typed GraphQL documents.
2311
+ *
2312
+ * @remarks
2313
+ * This accepts a {@link TadaDocumentNode} and returns the attached `Variables` type
2314
+ * of GraphQL documents.
2315
+ */
2316
+ type VariablesOf<Document> =
2317
+ Document extends DocumentDecoration<any, infer Variables> ? Variables : never;
2318
+ /** Creates a fragment mask for a given fragment document.
2319
+ *
2320
+ * @remarks
2321
+ * When {@link graphql} is used to create a fragment and is spread into another
2322
+ * fragment or query, their result types will only contain a “reference” to the
2323
+ * fragment. This encourages isolation and is known as “fragment masking.”
2324
+ *
2325
+ * While {@link readFragment} is used to unmask these fragment masks, this utility
2326
+ * creates a fragment mask, so you can accept the masked data in the part of your
2327
+ * codebase that defines a fragment.
2328
+ *
2329
+ * @example
2330
+ * ```
2331
+ * import { FragmentOf, graphql, readFragment } from 'gql.tada';
2332
+ *
2333
+ * const bookFragment = graphql(`
2334
+ * fragment BookComponent on Book {
2335
+ * id
2336
+ * title
2337
+ * }
2338
+ * `);
2339
+ *
2340
+ * // May be called with any GraphQL data that contains a spread of `bookFragment`
2341
+ * const getBook = (data: FragmentOf<typeof bookFragment>) => {
2342
+ * // Unmasks the fragment and casts to the result type of `bookFragment`
2343
+ * const book = readFragment(bookFragment, data);
2344
+ * };
2345
+ * ```
2346
+ *
2347
+ * @see {@link readFragment} for how to read from fragment masks.
2348
+ */
2349
+ type FragmentOf<Document extends FragmentShape> = makeFragmentRef<Document>;
2350
+ type resultOrFragmentOf<Document extends FragmentShape> = FragmentOf<Document> | ResultOf<Document>;
2351
+ type resultOfT<Document extends FragmentShape, T = unknown> =
2352
+ Document extends DocumentDecoration<infer Result, any>
2353
+ ? '__typename' extends keyof T
2354
+ ? Result extends {
2355
+ __typename?: T['__typename'];
2356
+ }
2357
+ ? Result
2358
+ : never
2359
+ : Result
2360
+ : never;
2361
+ /** Unmasks a fragment mask for a given fragment document and data.
2362
+ *
2363
+ * @param _document - A GraphQL document of a fragment, created using {@link graphql}.
2364
+ * @param fragment - A mask of the fragment, which can be wrapped in arrays, or nullable.
2365
+ * @returns The unmasked data of the fragment.
2366
+ *
2367
+ * @remarks
2368
+ * When {@link graphql} is used to create a fragment and is spread into another
2369
+ * fragment or query, their result types will only contain a “reference” to the
2370
+ * fragment. This encourages isolation and is known as “fragment masking.”
2371
+ *
2372
+ * This means that you must use {@link readFragment} to unmask these fragment masks
2373
+ * and get to the data. This encourages isolation and only using the data you define
2374
+ * a part of your codebase to require.
2375
+ *
2376
+ * @example
2377
+ * ```
2378
+ * import { FragmentOf, graphql, readFragment } from 'gql.tada';
2379
+ *
2380
+ * const bookFragment = graphql(`
2381
+ * fragment BookComponent on Book {
2382
+ * id
2383
+ * title
2384
+ * }
2385
+ * `);
2386
+ *
2387
+ * const getBook = (data: FragmentOf<typeof bookFragment> | null) => {
2388
+ * // Unmasks the fragment and casts to the result type of `bookFragment`
2389
+ * // This is intersected with `| null` in this case, due to the input type.
2390
+ * const book = readFragment(bookFragment, data);
2391
+ * };
2392
+ *
2393
+ * const bookQuery = graphql(`
2394
+ * query Book ($id: ID!) {
2395
+ * book(id: $id) {
2396
+ * id
2397
+ * ...BookComponent
2398
+ * }
2399
+ * }
2400
+ * `, [bookFragment]);
2401
+ *
2402
+ * const getQuery = (data: ResultOf<typeof bookQuery>) => {
2403
+ * getBook(data?.book);
2404
+ * };
2405
+ * ```
2406
+ *
2407
+ * @see {@link readFragment} for how to read from fragment masks.
2408
+ */
2409
+ declare function readFragment<const Document extends FragmentShape = never>(
2410
+ _document: Document,
2411
+ fragment: never
2412
+ ): resultOfT<Document>;
2413
+ declare function readFragment<
2414
+ const Document extends FragmentShape,
2415
+ const T extends resultOrFragmentOf<Document> | null | undefined | {},
2416
+ >(
2417
+ _document: Document,
2418
+ fragments: readonly T[]
2419
+ ): readonly (T extends resultOrFragmentOf<Document> ? resultOfT<Document, T> : T)[];
2420
+ declare function readFragment<
2421
+ const Document extends FragmentShape,
2422
+ const T extends resultOrFragmentOf<Document> | null | undefined | {},
2423
+ >(
2424
+ _document: Document,
2425
+ fragment: T
2426
+ ): T extends resultOrFragmentOf<Document> ? resultOfT<Document, T> : T;
2427
+ declare function readFragment<const Document extends FragmentShape>(
2428
+ fragment: readonly resultOrFragmentOf<Document>[]
2429
+ ): readonly ResultOf<Document>[];
2430
+ declare function readFragment<const Document extends FragmentShape>(
2431
+ fragment: readonly (resultOrFragmentOf<Document> | null)[]
2432
+ ): readonly (ResultOf<Document> | null)[];
2433
+ declare function readFragment<const Document extends FragmentShape>(
2434
+ fragment: readonly (resultOrFragmentOf<Document> | undefined)[]
2435
+ ): readonly (ResultOf<Document> | undefined)[];
2436
+ declare function readFragment<const Document extends FragmentShape>(
2437
+ fragment: readonly (resultOrFragmentOf<Document> | null | undefined)[]
2438
+ ): readonly (ResultOf<Document> | null | undefined)[];
2439
+ declare function readFragment<const Document extends FragmentShape>(
2440
+ fragment: readonly (resultOrFragmentOf<Document> | {})[]
2441
+ ): readonly (ResultOf<Document> | {})[];
2442
+ declare function readFragment<const Document extends FragmentShape>(
2443
+ fragment: readonly (resultOrFragmentOf<Document> | null | {})[]
2444
+ ): readonly (ResultOf<Document> | null | {})[];
2445
+ declare function readFragment<const Document extends FragmentShape>(
2446
+ fragment: readonly (resultOrFragmentOf<Document> | undefined | {})[]
2447
+ ): readonly (ResultOf<Document> | undefined | {})[];
2448
+ declare function readFragment<const Document extends FragmentShape>(
2449
+ fragment: readonly (resultOrFragmentOf<Document> | null | undefined | {})[]
2450
+ ): readonly (ResultOf<Document> | null | undefined | {})[];
2451
+ declare function readFragment<const Document extends FragmentShape>(
2452
+ fragment: resultOrFragmentOf<Document>
2453
+ ): ResultOf<Document>;
2454
+ declare function readFragment<const Document extends FragmentShape>(
2455
+ fragment: resultOrFragmentOf<Document> | null
2456
+ ): ResultOf<Document> | null;
2457
+ declare function readFragment<const Document extends FragmentShape>(
2458
+ fragment: resultOrFragmentOf<Document> | undefined
2459
+ ): ResultOf<Document> | undefined;
2460
+ declare function readFragment<const Document extends FragmentShape>(
2461
+ fragment: resultOrFragmentOf<Document> | null | undefined
2462
+ ): ResultOf<Document> | null | undefined;
2463
+ declare function readFragment<const Document extends FragmentShape>(
2464
+ fragment: resultOrFragmentOf<Document> | {}
2465
+ ): ResultOf<Document> | {};
2466
+ declare function readFragment<const Document extends FragmentShape>(
2467
+ fragment: resultOrFragmentOf<Document> | null | {}
2468
+ ): ResultOf<Document> | null | {};
2469
+ declare function readFragment<const Document extends FragmentShape>(
2470
+ fragment: resultOrFragmentOf<Document> | undefined | {}
2471
+ ): ResultOf<Document> | undefined | {};
2472
+ declare function readFragment<const Document extends FragmentShape>(
2473
+ fragment: resultOrFragmentOf<Document> | null | undefined | {}
2474
+ ): ResultOf<Document> | null | undefined | {};
2475
+ declare const graphql: initGraphQLTada<setupSchema>;
2476
+
2477
+ export {
2478
+ $tada as $,
2479
+ type AbstractSetupSchema as A,
2480
+ type DocumentDecoration as D,
2481
+ type FragmentOf as F,
2482
+ type GraphQLTadaAPI as G,
2483
+ type ResultOf as R,
2484
+ type TadaDocumentNode as T,
2485
+ type VariablesOf as V,
2486
+ readFragment as a,
2487
+ type setupSchema as b,
2488
+ type parseDocument as c,
2489
+ type AbstractSetupCache as d,
2490
+ type TadaPersistedDocumentNode as e,
2491
+ type mapType as f,
2492
+ graphql as g,
2493
+ initGraphQLTada as i,
2494
+ maskFragments as m,
2495
+ parse as p,
2496
+ readResult as r,
2497
+ type setupCache as s,
2498
+ unsafe_readResult as u,
2499
+ };