goatly 0.1.0 → 0.1.2

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