quicktype-graphql-input 0.0.57 → 0.0.58

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,645 @@
1
+ export declare enum __DirectiveLocation {
2
+ QUERY = "QUERY",
3
+ MUTATION = "MUTATION",
4
+ SUBSCRIPTION = "SUBSCRIPTION",
5
+ FIELD = "FIELD",
6
+ FRAGMENT_DEFINITION = "FRAGMENT_DEFINITION",
7
+ FRAGMENT_SPREAD = "FRAGMENT_SPREAD",
8
+ INLINE_FRAGMENT = "INLINE_FRAGMENT",
9
+ SCHEMA = "SCHEMA",
10
+ SCALAR = "SCALAR",
11
+ OBJECT = "OBJECT",
12
+ FIELD_DEFINITION = "FIELD_DEFINITION",
13
+ ARGUMENT_DEFINITION = "ARGUMENT_DEFINITION",
14
+ INTERFACE = "INTERFACE",
15
+ UNION = "UNION",
16
+ ENUM = "ENUM",
17
+ ENUM_VALUE = "ENUM_VALUE",
18
+ INPUT_OBJECT = "INPUT_OBJECT",
19
+ INPUT_FIELD_DEFINITION = "INPUT_FIELD_DEFINITION"
20
+ }
21
+ export declare enum TypeKind {
22
+ SCALAR = "SCALAR",
23
+ OBJECT = "OBJECT",
24
+ INTERFACE = "INTERFACE",
25
+ UNION = "UNION",
26
+ ENUM = "ENUM",
27
+ INPUT_OBJECT = "INPUT_OBJECT",
28
+ LIST = "LIST",
29
+ NON_NULL = "NON_NULL"
30
+ }
31
+ export declare type GraphQLSchema = {
32
+ __schema: {
33
+ __typename: "__Schema";
34
+ queryType: {
35
+ __typename: "__Type";
36
+ name: string | null;
37
+ };
38
+ mutationType: {
39
+ __typename: "__Type";
40
+ name: string | null;
41
+ } | null;
42
+ subscriptionType: {
43
+ __typename: "__Type";
44
+ name: string | null;
45
+ } | null;
46
+ types: Array<{
47
+ __typename: "__Type";
48
+ kind: TypeKind;
49
+ name: string | null;
50
+ description: string | null;
51
+ fields: Array<{
52
+ __typename: "__Field";
53
+ name: string;
54
+ description: string | null;
55
+ args: Array<{
56
+ __typename: "__InputValue";
57
+ name: string;
58
+ description: string | null;
59
+ type: {
60
+ __typename: "__Type";
61
+ kind: TypeKind;
62
+ name: string | null;
63
+ ofType: {
64
+ __typename: "__Type";
65
+ kind: TypeKind;
66
+ name: string | null;
67
+ ofType: {
68
+ __typename: "__Type";
69
+ kind: TypeKind;
70
+ name: string | null;
71
+ ofType: {
72
+ __typename: "__Type";
73
+ kind: TypeKind;
74
+ name: string | null;
75
+ ofType: {
76
+ __typename: "__Type";
77
+ kind: TypeKind;
78
+ name: string | null;
79
+ ofType: {
80
+ __typename: "__Type";
81
+ kind: TypeKind;
82
+ name: string | null;
83
+ ofType: {
84
+ __typename: "__Type";
85
+ kind: TypeKind;
86
+ name: string | null;
87
+ ofType: {
88
+ __typename: "__Type";
89
+ kind: TypeKind;
90
+ name: string | null;
91
+ } | null;
92
+ } | null;
93
+ } | null;
94
+ } | null;
95
+ } | null;
96
+ } | null;
97
+ } | null;
98
+ };
99
+ defaultValue: string | null;
100
+ }>;
101
+ type: {
102
+ __typename: "__Type";
103
+ kind: TypeKind;
104
+ name: string | null;
105
+ ofType: {
106
+ __typename: "__Type";
107
+ kind: TypeKind;
108
+ name: string | null;
109
+ ofType: {
110
+ __typename: "__Type";
111
+ kind: TypeKind;
112
+ name: string | null;
113
+ ofType: {
114
+ __typename: "__Type";
115
+ kind: TypeKind;
116
+ name: string | null;
117
+ ofType: {
118
+ __typename: "__Type";
119
+ kind: TypeKind;
120
+ name: string | null;
121
+ ofType: {
122
+ __typename: "__Type";
123
+ kind: TypeKind;
124
+ name: string | null;
125
+ ofType: {
126
+ __typename: "__Type";
127
+ kind: TypeKind;
128
+ name: string | null;
129
+ ofType: {
130
+ __typename: "__Type";
131
+ kind: TypeKind;
132
+ name: string | null;
133
+ } | null;
134
+ } | null;
135
+ } | null;
136
+ } | null;
137
+ } | null;
138
+ } | null;
139
+ } | null;
140
+ };
141
+ isDeprecated: boolean;
142
+ deprecationReason: string | null;
143
+ }> | null;
144
+ inputFields: Array<{
145
+ __typename: "__InputValue";
146
+ name: string;
147
+ description: string | null;
148
+ type: {
149
+ __typename: "__Type";
150
+ kind: TypeKind;
151
+ name: string | null;
152
+ ofType: {
153
+ __typename: "__Type";
154
+ kind: TypeKind;
155
+ name: string | null;
156
+ ofType: {
157
+ __typename: "__Type";
158
+ kind: TypeKind;
159
+ name: string | null;
160
+ ofType: {
161
+ __typename: "__Type";
162
+ kind: TypeKind;
163
+ name: string | null;
164
+ ofType: {
165
+ __typename: "__Type";
166
+ kind: TypeKind;
167
+ name: string | null;
168
+ ofType: {
169
+ __typename: "__Type";
170
+ kind: TypeKind;
171
+ name: string | null;
172
+ ofType: {
173
+ __typename: "__Type";
174
+ kind: TypeKind;
175
+ name: string | null;
176
+ ofType: {
177
+ __typename: "__Type";
178
+ kind: TypeKind;
179
+ name: string | null;
180
+ } | null;
181
+ } | null;
182
+ } | null;
183
+ } | null;
184
+ } | null;
185
+ } | null;
186
+ } | null;
187
+ };
188
+ defaultValue: string | null;
189
+ }> | null;
190
+ interfaces: Array<{
191
+ __typename: "__Type";
192
+ kind: TypeKind;
193
+ name: string | null;
194
+ ofType: {
195
+ __typename: "__Type";
196
+ kind: TypeKind;
197
+ name: string | null;
198
+ ofType: {
199
+ __typename: "__Type";
200
+ kind: TypeKind;
201
+ name: string | null;
202
+ ofType: {
203
+ __typename: "__Type";
204
+ kind: TypeKind;
205
+ name: string | null;
206
+ ofType: {
207
+ __typename: "__Type";
208
+ kind: TypeKind;
209
+ name: string | null;
210
+ ofType: {
211
+ __typename: "__Type";
212
+ kind: TypeKind;
213
+ name: string | null;
214
+ ofType: {
215
+ __typename: "__Type";
216
+ kind: TypeKind;
217
+ name: string | null;
218
+ ofType: {
219
+ __typename: "__Type";
220
+ kind: TypeKind;
221
+ name: string | null;
222
+ } | null;
223
+ } | null;
224
+ } | null;
225
+ } | null;
226
+ } | null;
227
+ } | null;
228
+ } | null;
229
+ }> | null;
230
+ enumValues: Array<{
231
+ __typename: "__EnumValue";
232
+ name: string;
233
+ description: string | null;
234
+ }> | null;
235
+ possibleTypes: Array<{
236
+ __typename: "__Type";
237
+ kind: TypeKind;
238
+ name: string | null;
239
+ ofType: {
240
+ __typename: "__Type";
241
+ kind: TypeKind;
242
+ name: string | null;
243
+ ofType: {
244
+ __typename: "__Type";
245
+ kind: TypeKind;
246
+ name: string | null;
247
+ ofType: {
248
+ __typename: "__Type";
249
+ kind: TypeKind;
250
+ name: string | null;
251
+ ofType: {
252
+ __typename: "__Type";
253
+ kind: TypeKind;
254
+ name: string | null;
255
+ ofType: {
256
+ __typename: "__Type";
257
+ kind: TypeKind;
258
+ name: string | null;
259
+ ofType: {
260
+ __typename: "__Type";
261
+ kind: TypeKind;
262
+ name: string | null;
263
+ ofType: {
264
+ __typename: "__Type";
265
+ kind: TypeKind;
266
+ name: string | null;
267
+ } | null;
268
+ } | null;
269
+ } | null;
270
+ } | null;
271
+ } | null;
272
+ } | null;
273
+ } | null;
274
+ }> | null;
275
+ }>;
276
+ directives: Array<{
277
+ __typename: "__Directive";
278
+ name: string;
279
+ description: string | null;
280
+ locations: Array<__DirectiveLocation>;
281
+ args: Array<{
282
+ __typename: "__InputValue";
283
+ name: string;
284
+ description: string | null;
285
+ type: {
286
+ __typename: "__Type";
287
+ kind: TypeKind;
288
+ name: string | null;
289
+ ofType: {
290
+ __typename: "__Type";
291
+ kind: TypeKind;
292
+ name: string | null;
293
+ ofType: {
294
+ __typename: "__Type";
295
+ kind: TypeKind;
296
+ name: string | null;
297
+ ofType: {
298
+ __typename: "__Type";
299
+ kind: TypeKind;
300
+ name: string | null;
301
+ ofType: {
302
+ __typename: "__Type";
303
+ kind: TypeKind;
304
+ name: string | null;
305
+ ofType: {
306
+ __typename: "__Type";
307
+ kind: TypeKind;
308
+ name: string | null;
309
+ ofType: {
310
+ __typename: "__Type";
311
+ kind: TypeKind;
312
+ name: string | null;
313
+ ofType: {
314
+ __typename: "__Type";
315
+ kind: TypeKind;
316
+ name: string | null;
317
+ } | null;
318
+ } | null;
319
+ } | null;
320
+ } | null;
321
+ } | null;
322
+ } | null;
323
+ } | null;
324
+ };
325
+ defaultValue: string | null;
326
+ }>;
327
+ }>;
328
+ };
329
+ };
330
+ export declare type FullTypeFragment = {
331
+ __typename: "__Type";
332
+ kind: TypeKind;
333
+ name: string | null;
334
+ description: string | null;
335
+ fields: Array<{
336
+ __typename: string;
337
+ name: string;
338
+ description: string | null;
339
+ args: Array<{
340
+ __typename: string;
341
+ name: string;
342
+ description: string | null;
343
+ type: {
344
+ __typename: string;
345
+ kind: TypeKind;
346
+ name: string | null;
347
+ ofType: {
348
+ __typename: string;
349
+ kind: TypeKind;
350
+ name: string | null;
351
+ ofType: {
352
+ __typename: string;
353
+ kind: TypeKind;
354
+ name: string | null;
355
+ ofType: {
356
+ __typename: string;
357
+ kind: TypeKind;
358
+ name: string | null;
359
+ ofType: {
360
+ __typename: string;
361
+ kind: TypeKind;
362
+ name: string | null;
363
+ ofType: {
364
+ __typename: string;
365
+ kind: TypeKind;
366
+ name: string | null;
367
+ ofType: {
368
+ __typename: string;
369
+ kind: TypeKind;
370
+ name: string | null;
371
+ ofType: {
372
+ __typename: string;
373
+ kind: TypeKind;
374
+ name: string | null;
375
+ } | null;
376
+ } | null;
377
+ } | null;
378
+ } | null;
379
+ } | null;
380
+ } | null;
381
+ } | null;
382
+ };
383
+ defaultValue: string | null;
384
+ }>;
385
+ type: {
386
+ __typename: string;
387
+ kind: TypeKind;
388
+ name: string | null;
389
+ ofType: {
390
+ __typename: string;
391
+ kind: TypeKind;
392
+ name: string | null;
393
+ ofType: {
394
+ __typename: string;
395
+ kind: TypeKind;
396
+ name: string | null;
397
+ ofType: {
398
+ __typename: string;
399
+ kind: TypeKind;
400
+ name: string | null;
401
+ ofType: {
402
+ __typename: string;
403
+ kind: TypeKind;
404
+ name: string | null;
405
+ ofType: {
406
+ __typename: string;
407
+ kind: TypeKind;
408
+ name: string | null;
409
+ ofType: {
410
+ __typename: string;
411
+ kind: TypeKind;
412
+ name: string | null;
413
+ ofType: {
414
+ __typename: string;
415
+ kind: TypeKind;
416
+ name: string | null;
417
+ } | null;
418
+ } | null;
419
+ } | null;
420
+ } | null;
421
+ } | null;
422
+ } | null;
423
+ } | null;
424
+ };
425
+ isDeprecated: boolean;
426
+ deprecationReason: string | null;
427
+ }> | null;
428
+ inputFields: Array<{
429
+ __typename: string;
430
+ name: string;
431
+ description: string | null;
432
+ type: {
433
+ __typename: string;
434
+ kind: TypeKind;
435
+ name: string | null;
436
+ ofType: {
437
+ __typename: string;
438
+ kind: TypeKind;
439
+ name: string | null;
440
+ ofType: {
441
+ __typename: string;
442
+ kind: TypeKind;
443
+ name: string | null;
444
+ ofType: {
445
+ __typename: string;
446
+ kind: TypeKind;
447
+ name: string | null;
448
+ ofType: {
449
+ __typename: string;
450
+ kind: TypeKind;
451
+ name: string | null;
452
+ ofType: {
453
+ __typename: string;
454
+ kind: TypeKind;
455
+ name: string | null;
456
+ ofType: {
457
+ __typename: string;
458
+ kind: TypeKind;
459
+ name: string | null;
460
+ ofType: {
461
+ __typename: string;
462
+ kind: TypeKind;
463
+ name: string | null;
464
+ } | null;
465
+ } | null;
466
+ } | null;
467
+ } | null;
468
+ } | null;
469
+ } | null;
470
+ } | null;
471
+ };
472
+ defaultValue: string | null;
473
+ }> | null;
474
+ interfaces: Array<{
475
+ __typename: string;
476
+ kind: TypeKind;
477
+ name: string | null;
478
+ ofType: {
479
+ __typename: string;
480
+ kind: TypeKind;
481
+ name: string | null;
482
+ ofType: {
483
+ __typename: string;
484
+ kind: TypeKind;
485
+ name: string | null;
486
+ ofType: {
487
+ __typename: string;
488
+ kind: TypeKind;
489
+ name: string | null;
490
+ ofType: {
491
+ __typename: string;
492
+ kind: TypeKind;
493
+ name: string | null;
494
+ ofType: {
495
+ __typename: string;
496
+ kind: TypeKind;
497
+ name: string | null;
498
+ ofType: {
499
+ __typename: string;
500
+ kind: TypeKind;
501
+ name: string | null;
502
+ ofType: {
503
+ __typename: string;
504
+ kind: TypeKind;
505
+ name: string | null;
506
+ } | null;
507
+ } | null;
508
+ } | null;
509
+ } | null;
510
+ } | null;
511
+ } | null;
512
+ } | null;
513
+ }> | null;
514
+ enumValues: Array<{
515
+ __typename: string;
516
+ name: string;
517
+ description: string | null;
518
+ }> | null;
519
+ possibleTypes: Array<{
520
+ __typename: string;
521
+ kind: TypeKind;
522
+ name: string | null;
523
+ ofType: {
524
+ __typename: string;
525
+ kind: TypeKind;
526
+ name: string | null;
527
+ ofType: {
528
+ __typename: string;
529
+ kind: TypeKind;
530
+ name: string | null;
531
+ ofType: {
532
+ __typename: string;
533
+ kind: TypeKind;
534
+ name: string | null;
535
+ ofType: {
536
+ __typename: string;
537
+ kind: TypeKind;
538
+ name: string | null;
539
+ ofType: {
540
+ __typename: string;
541
+ kind: TypeKind;
542
+ name: string | null;
543
+ ofType: {
544
+ __typename: string;
545
+ kind: TypeKind;
546
+ name: string | null;
547
+ ofType: {
548
+ __typename: string;
549
+ kind: TypeKind;
550
+ name: string | null;
551
+ } | null;
552
+ } | null;
553
+ } | null;
554
+ } | null;
555
+ } | null;
556
+ } | null;
557
+ } | null;
558
+ }> | null;
559
+ };
560
+ export declare type InputValueFragment = {
561
+ __typename: "__InputValue";
562
+ name: string;
563
+ description: string | null;
564
+ type: {
565
+ __typename: string;
566
+ kind: TypeKind;
567
+ name: string | null;
568
+ ofType: {
569
+ __typename: string;
570
+ kind: TypeKind;
571
+ name: string | null;
572
+ ofType: {
573
+ __typename: string;
574
+ kind: TypeKind;
575
+ name: string | null;
576
+ ofType: {
577
+ __typename: string;
578
+ kind: TypeKind;
579
+ name: string | null;
580
+ ofType: {
581
+ __typename: string;
582
+ kind: TypeKind;
583
+ name: string | null;
584
+ ofType: {
585
+ __typename: string;
586
+ kind: TypeKind;
587
+ name: string | null;
588
+ ofType: {
589
+ __typename: string;
590
+ kind: TypeKind;
591
+ name: string | null;
592
+ ofType: {
593
+ __typename: string;
594
+ kind: TypeKind;
595
+ name: string | null;
596
+ } | null;
597
+ } | null;
598
+ } | null;
599
+ } | null;
600
+ } | null;
601
+ } | null;
602
+ } | null;
603
+ };
604
+ defaultValue: string | null;
605
+ };
606
+ export declare type TypeRefFragment = {
607
+ __typename: "__Type";
608
+ kind: TypeKind;
609
+ name: string | null;
610
+ ofType: {
611
+ __typename: string;
612
+ kind: TypeKind;
613
+ name: string | null;
614
+ ofType: {
615
+ __typename: string;
616
+ kind: TypeKind;
617
+ name: string | null;
618
+ ofType: {
619
+ __typename: string;
620
+ kind: TypeKind;
621
+ name: string | null;
622
+ ofType: {
623
+ __typename: string;
624
+ kind: TypeKind;
625
+ name: string | null;
626
+ ofType: {
627
+ __typename: string;
628
+ kind: TypeKind;
629
+ name: string | null;
630
+ ofType: {
631
+ __typename: string;
632
+ kind: TypeKind;
633
+ name: string | null;
634
+ ofType: {
635
+ __typename: string;
636
+ kind: TypeKind;
637
+ name: string | null;
638
+ } | null;
639
+ } | null;
640
+ } | null;
641
+ } | null;
642
+ } | null;
643
+ } | null;
644
+ } | null;
645
+ };
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /* tslint:disable */
3
+ // This file was automatically generated and should not be edited.
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ // A Directive can be adjacent to many parts of the GraphQL language, a __DirectiveLocation describes one such possible adjacencies.
6
+ var __DirectiveLocation;
7
+ (function (__DirectiveLocation) {
8
+ __DirectiveLocation["QUERY"] = "QUERY";
9
+ __DirectiveLocation["MUTATION"] = "MUTATION";
10
+ __DirectiveLocation["SUBSCRIPTION"] = "SUBSCRIPTION";
11
+ __DirectiveLocation["FIELD"] = "FIELD";
12
+ __DirectiveLocation["FRAGMENT_DEFINITION"] = "FRAGMENT_DEFINITION";
13
+ __DirectiveLocation["FRAGMENT_SPREAD"] = "FRAGMENT_SPREAD";
14
+ __DirectiveLocation["INLINE_FRAGMENT"] = "INLINE_FRAGMENT";
15
+ __DirectiveLocation["SCHEMA"] = "SCHEMA";
16
+ __DirectiveLocation["SCALAR"] = "SCALAR";
17
+ __DirectiveLocation["OBJECT"] = "OBJECT";
18
+ __DirectiveLocation["FIELD_DEFINITION"] = "FIELD_DEFINITION";
19
+ __DirectiveLocation["ARGUMENT_DEFINITION"] = "ARGUMENT_DEFINITION";
20
+ __DirectiveLocation["INTERFACE"] = "INTERFACE";
21
+ __DirectiveLocation["UNION"] = "UNION";
22
+ __DirectiveLocation["ENUM"] = "ENUM";
23
+ __DirectiveLocation["ENUM_VALUE"] = "ENUM_VALUE";
24
+ __DirectiveLocation["INPUT_OBJECT"] = "INPUT_OBJECT";
25
+ __DirectiveLocation["INPUT_FIELD_DEFINITION"] = "INPUT_FIELD_DEFINITION"; // Location adjacent to an input object field definition.
26
+ })(__DirectiveLocation = exports.__DirectiveLocation || (exports.__DirectiveLocation = {}));
27
+ // An enum describing what kind of type a given `__Type` is.
28
+ var TypeKind;
29
+ (function (TypeKind) {
30
+ TypeKind["SCALAR"] = "SCALAR";
31
+ TypeKind["OBJECT"] = "OBJECT";
32
+ TypeKind["INTERFACE"] = "INTERFACE";
33
+ TypeKind["UNION"] = "UNION";
34
+ TypeKind["ENUM"] = "ENUM";
35
+ TypeKind["INPUT_OBJECT"] = "INPUT_OBJECT";
36
+ TypeKind["LIST"] = "LIST";
37
+ TypeKind["NON_NULL"] = "NON_NULL"; // Indicates this type is a non-null. `ofType` is a valid field.
38
+ })(TypeKind = exports.TypeKind || (exports.TypeKind = {}));
@@ -0,0 +1,17 @@
1
+ import { TypeBuilder, Input, RunContext } from "quicktype-core";
2
+ export declare type GraphQLSourceData = {
3
+ name: string;
4
+ schema: any;
5
+ query: string;
6
+ };
7
+ export declare class GraphQLInput implements Input<GraphQLSourceData> {
8
+ readonly kind: string;
9
+ readonly needIR: boolean;
10
+ readonly needSchemaProcessing: boolean;
11
+ private readonly _topLevels;
12
+ addSource(source: GraphQLSourceData): Promise<void>;
13
+ addSourceSync(source: GraphQLSourceData): void;
14
+ singleStringSchemaSource(): undefined;
15
+ addTypes(ctx: RunContext, typeBuilder: TypeBuilder): Promise<void>;
16
+ addTypesSync(_ctx: RunContext, typeBuilder: TypeBuilder): void;
17
+ }
package/dist/index.js ADDED
@@ -0,0 +1,390 @@
1
+ "use strict";
2
+ /* tslint:disable:strict-boolean-expressions */
3
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const graphql = require("graphql/language");
13
+ const collection_utils_1 = require("collection-utils");
14
+ const quicktype_core_1 = require("quicktype-core");
15
+ const GraphQLSchema_1 = require("./GraphQLSchema");
16
+ function getField(t, name) {
17
+ if (!t.fields)
18
+ return quicktype_core_1.panic(`Required field ${name} in type ${t.name} which doesn't have fields.`);
19
+ for (const f of t.fields) {
20
+ if (f.name === name) {
21
+ return f;
22
+ }
23
+ }
24
+ return quicktype_core_1.panic(`Required field ${name} not defined on type ${t.name}.`);
25
+ }
26
+ function makeNames(name, fieldName, containingTypeName) {
27
+ const alternatives = [];
28
+ if (fieldName)
29
+ alternatives.push(fieldName);
30
+ if (containingTypeName)
31
+ alternatives.push(`${containingTypeName}_${name}`);
32
+ if (fieldName && containingTypeName)
33
+ alternatives.push(`${containingTypeName}_${fieldName}`);
34
+ return quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set([name]), new Set(alternatives), false));
35
+ }
36
+ function makeNullable(builder, tref, name, fieldName, containingTypeName) {
37
+ const typeNames = makeNames(name, fieldName, containingTypeName);
38
+ const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
39
+ if (!(t instanceof quicktype_core_1.UnionType)) {
40
+ return builder.getUnionType(typeNames, new Set([tref, builder.getPrimitiveType("null")]));
41
+ }
42
+ const [maybeNull, nonNulls] = quicktype_core_1.removeNullFromUnion(t);
43
+ if (maybeNull)
44
+ return tref;
45
+ return builder.getUnionType(typeNames, collection_utils_1.setMap(nonNulls, nn => nn.typeRef).add(builder.getPrimitiveType("null")));
46
+ }
47
+ // This is really not the way to do this, but it's easy and works. By default
48
+ // all types in GraphQL are nullable, and non-nullability must be specially marked,
49
+ // so we just construct a nullable type first, and then remove the null from the
50
+ // union if the type is modified to be non-nullable. That means that the union
51
+ // (and the null) might be left unreachable in the graph. Provenance checking
52
+ // won't work in this case, which is why it's disabled in testing for GraphQL.
53
+ function removeNull(builder, tref) {
54
+ const t = quicktype_core_1.derefTypeRef(tref, builder.typeGraph);
55
+ if (!(t instanceof quicktype_core_1.UnionType)) {
56
+ return tref;
57
+ }
58
+ const nonNulls = quicktype_core_1.removeNullFromUnion(t)[1];
59
+ const first = collection_utils_1.iterableFirst(nonNulls);
60
+ if (first) {
61
+ if (nonNulls.size === 1)
62
+ return first.typeRef;
63
+ return builder.getUnionType(t.getAttributes(), collection_utils_1.setMap(nonNulls, nn => nn.typeRef));
64
+ }
65
+ return quicktype_core_1.panic("Trying to remove null results in empty union.");
66
+ }
67
+ function makeScalar(builder, ft) {
68
+ switch (ft.name) {
69
+ case "Boolean":
70
+ return builder.getPrimitiveType("bool");
71
+ case "Int":
72
+ return builder.getPrimitiveType("integer");
73
+ case "Float":
74
+ return builder.getPrimitiveType("double");
75
+ default:
76
+ // FIXME: support ID specifically?
77
+ return builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted);
78
+ }
79
+ }
80
+ function hasOptionalDirectives(directives) {
81
+ if (!directives)
82
+ return false;
83
+ for (const d of directives) {
84
+ const name = d.name.value;
85
+ if (name === "include" || name === "skip")
86
+ return true;
87
+ }
88
+ return false;
89
+ }
90
+ function expandSelectionSet(selectionSet, inType, optional) {
91
+ return selectionSet.selections
92
+ .reverse()
93
+ .map(s => ({ selection: s, inType, optional: optional || hasOptionalDirectives(s.directives) }));
94
+ }
95
+ class GQLQuery {
96
+ constructor(schema, queryString) {
97
+ this.makeIRTypeFromFieldNode = (builder, fieldNode, fieldType, containingTypeName) => {
98
+ let optional = hasOptionalDirectives(fieldNode.directives);
99
+ let result;
100
+ switch (fieldType.kind) {
101
+ case GraphQLSchema_1.TypeKind.SCALAR:
102
+ result = makeScalar(builder, fieldType);
103
+ optional = true;
104
+ break;
105
+ case GraphQLSchema_1.TypeKind.OBJECT:
106
+ case GraphQLSchema_1.TypeKind.INTERFACE:
107
+ case GraphQLSchema_1.TypeKind.UNION:
108
+ if (!fieldNode.selectionSet) {
109
+ return quicktype_core_1.panic("No selection set on object or interface");
110
+ }
111
+ return makeNullable(builder, this.makeIRTypeFromSelectionSet(builder, fieldNode.selectionSet, fieldType, fieldNode.name.value, containingTypeName), fieldNode.name.value, null, containingTypeName);
112
+ case GraphQLSchema_1.TypeKind.ENUM:
113
+ if (!fieldType.enumValues) {
114
+ return quicktype_core_1.panic("Enum type doesn't have values");
115
+ }
116
+ const values = fieldType.enumValues.map(ev => ev.name);
117
+ let name;
118
+ let fieldName;
119
+ if (fieldType.name) {
120
+ name = fieldType.name;
121
+ fieldName = fieldNode.name.value;
122
+ }
123
+ else {
124
+ name = fieldNode.name.value;
125
+ fieldName = null;
126
+ }
127
+ optional = true;
128
+ result = builder.getEnumType(makeNames(name, fieldName, containingTypeName), new Set(values));
129
+ break;
130
+ case GraphQLSchema_1.TypeKind.INPUT_OBJECT:
131
+ // FIXME: Support input objects
132
+ return quicktype_core_1.panic("Input objects not supported");
133
+ case GraphQLSchema_1.TypeKind.LIST:
134
+ if (!fieldType.ofType) {
135
+ return quicktype_core_1.panic("No type for list");
136
+ }
137
+ result = builder.getArrayType(quicktype_core_1.emptyTypeAttributes, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
138
+ break;
139
+ case GraphQLSchema_1.TypeKind.NON_NULL:
140
+ if (!fieldType.ofType) {
141
+ return quicktype_core_1.panic("No type for non-null");
142
+ }
143
+ result = removeNull(builder, this.makeIRTypeFromFieldNode(builder, fieldNode, fieldType.ofType, containingTypeName));
144
+ break;
145
+ default:
146
+ return quicktype_core_1.assertNever(fieldType.kind);
147
+ }
148
+ if (optional) {
149
+ result = makeNullable(builder, result, fieldNode.name.value, null, containingTypeName);
150
+ }
151
+ return result;
152
+ };
153
+ this.getFragment = (name) => {
154
+ const fragment = this._fragments[name];
155
+ if (!fragment)
156
+ return quicktype_core_1.panic(`Fragment ${name} is not defined.`);
157
+ return fragment;
158
+ };
159
+ this.makeIRTypeFromSelectionSet = (builder, selectionSet, gqlType, containingFieldName, containingTypeName, overrideName) => {
160
+ if (gqlType.kind !== GraphQLSchema_1.TypeKind.OBJECT &&
161
+ gqlType.kind !== GraphQLSchema_1.TypeKind.INTERFACE &&
162
+ gqlType.kind !== GraphQLSchema_1.TypeKind.UNION) {
163
+ return quicktype_core_1.panic("Type for selection set is not object, interface, or union.");
164
+ }
165
+ if (!gqlType.name) {
166
+ return quicktype_core_1.panic("Object, interface, or union type doesn't have a name.");
167
+ }
168
+ const nameOrOverride = overrideName || gqlType.name;
169
+ const properties = new Map();
170
+ let selections = expandSelectionSet(selectionSet, gqlType, false);
171
+ for (;;) {
172
+ const nextItem = selections.pop();
173
+ if (!nextItem)
174
+ break;
175
+ const { selection, optional, inType } = nextItem;
176
+ switch (selection.kind) {
177
+ case "Field":
178
+ const fieldName = selection.name.value;
179
+ const givenName = selection.alias ? selection.alias.value : fieldName;
180
+ const field = getField(inType, fieldName);
181
+ let fieldType = this.makeIRTypeFromFieldNode(builder, selection, field.type, nameOrOverride);
182
+ properties.set(givenName, builder.makeClassProperty(fieldType, optional));
183
+ break;
184
+ case "FragmentSpread": {
185
+ const fragment = this.getFragment(selection.name.value);
186
+ const fragmentType = this._schema.types[fragment.typeCondition.name.value];
187
+ const fragmentOptional = optional || fragmentType.name !== inType.name;
188
+ const expanded = expandSelectionSet(fragment.selectionSet, fragmentType, fragmentOptional);
189
+ selections = selections.concat(expanded);
190
+ break;
191
+ }
192
+ case "InlineFragment": {
193
+ // FIXME: support type conditions with discriminated unions
194
+ const fragmentType = selection.typeCondition
195
+ ? this._schema.types[selection.typeCondition.name.value]
196
+ : inType;
197
+ const fragmentOptional = optional || fragmentType.name !== inType.name || hasOptionalDirectives(selection.directives);
198
+ const expanded = expandSelectionSet(selection.selectionSet, fragmentType, fragmentOptional);
199
+ selections = selections.concat(expanded);
200
+ break;
201
+ }
202
+ default:
203
+ quicktype_core_1.assertNever(selection);
204
+ }
205
+ }
206
+ return builder.getClassType(makeNames(nameOrOverride, containingFieldName, containingTypeName), properties);
207
+ };
208
+ this._schema = schema;
209
+ this._fragments = {};
210
+ const queryDocument = graphql.parse(queryString);
211
+ const queries = [];
212
+ for (const def of queryDocument.definitions) {
213
+ if (def.kind === "OperationDefinition") {
214
+ if (def.operation === "query" || def.operation === "mutation") {
215
+ queries.push(def);
216
+ }
217
+ }
218
+ else if (def.kind === "FragmentDefinition") {
219
+ this._fragments[def.name.value] = def;
220
+ }
221
+ }
222
+ quicktype_core_1.messageAssert(queries.length >= 1, "GraphQLNoQueriesDefined", {});
223
+ this.queries = queries;
224
+ }
225
+ makeType(builder, query, queryName) {
226
+ if (query.operation === "query") {
227
+ return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.queryType, null, queryName, "data");
228
+ }
229
+ if (query.operation === "mutation") {
230
+ if (this._schema.mutationType === undefined) {
231
+ return quicktype_core_1.panic("This GraphQL endpoint has no mutations.");
232
+ }
233
+ return this.makeIRTypeFromSelectionSet(builder, query.selectionSet, this._schema.mutationType, null, queryName, "data");
234
+ }
235
+ return quicktype_core_1.panic(`Unknown query operation type: "${query.operation}"`);
236
+ }
237
+ }
238
+ class GQLSchemaFromJSON {
239
+ constructor(json) {
240
+ this.types = {};
241
+ this.addTypeFields = (target, source) => {
242
+ if (source.fields) {
243
+ target.fields = source.fields.map(f => {
244
+ return {
245
+ name: f.name,
246
+ description: f.description,
247
+ type: this.makeType(f.type),
248
+ args: f.args.map(this.makeInputValue)
249
+ };
250
+ });
251
+ // console.log(`${target.name} has ${target.fields.length} fields`);
252
+ }
253
+ if (source.interfaces) {
254
+ target.interfaces = source.interfaces.map(this.makeType);
255
+ // console.log(`${target.name} has ${target.interfaces.length} interfaces`);
256
+ }
257
+ if (source.possibleTypes) {
258
+ target.possibleTypes = source.possibleTypes.map(this.makeType);
259
+ // console.log(`${target.name} has ${target.possibleTypes.length} possibleTypes`);
260
+ }
261
+ if (source.inputFields) {
262
+ target.inputFields = source.inputFields.map(this.makeInputValue);
263
+ // console.log(`${target.name} has ${target.inputFields.length} inputFields`);
264
+ }
265
+ if (source.enumValues) {
266
+ target.enumValues = source.enumValues.map(ev => {
267
+ return { name: ev.name, description: ev.description };
268
+ });
269
+ // console.log(`${target.name} has ${target.enumValues.length} enumValues`);
270
+ }
271
+ };
272
+ this.makeInputValue = (iv) => {
273
+ return {
274
+ name: iv.name,
275
+ description: iv.description,
276
+ type: this.makeType(iv.type),
277
+ defaultValue: iv.defaultValue
278
+ };
279
+ };
280
+ this.makeType = (t) => {
281
+ if (t.name) {
282
+ const namedType = this.types[t.name];
283
+ if (!namedType)
284
+ return quicktype_core_1.panic(`Type ${t.name} not found`);
285
+ return namedType;
286
+ }
287
+ if (!t.ofType)
288
+ return quicktype_core_1.panic(`Type of kind ${t.kind} has neither name nor ofType`);
289
+ const type = {
290
+ kind: t.kind,
291
+ description: t.description,
292
+ ofType: this.makeType(t.ofType)
293
+ };
294
+ this.addTypeFields(type, t);
295
+ return type;
296
+ };
297
+ const schema = json.data;
298
+ if (schema.__schema.queryType.name === null) {
299
+ return quicktype_core_1.panic("Query type doesn't have a name.");
300
+ }
301
+ for (const t of schema.__schema.types) {
302
+ if (!t.name)
303
+ return quicktype_core_1.panic("No top-level type name given");
304
+ this.types[t.name] = { kind: t.kind, name: t.name, description: t.description };
305
+ }
306
+ for (const t of schema.__schema.types) {
307
+ if (!t.name)
308
+ return quicktype_core_1.panic("This cannot happen");
309
+ const type = this.types[t.name];
310
+ this.addTypeFields(type, t);
311
+ // console.log(`type ${type.name} is ${type.kind}`);
312
+ }
313
+ const queryType = this.types[schema.__schema.queryType.name];
314
+ if (queryType === undefined) {
315
+ return quicktype_core_1.panic("Query type not found.");
316
+ }
317
+ // console.log(`query type ${queryType.name} is ${queryType.kind}`);
318
+ this.queryType = queryType;
319
+ if (schema.__schema.mutationType === null) {
320
+ return;
321
+ }
322
+ if (schema.__schema.mutationType.name === null) {
323
+ return quicktype_core_1.panic("Mutation type doesn't have a name.");
324
+ }
325
+ const mutationType = this.types[schema.__schema.mutationType.name];
326
+ if (mutationType === undefined) {
327
+ return quicktype_core_1.panic("Mutation type not found.");
328
+ }
329
+ this.mutationType = mutationType;
330
+ }
331
+ }
332
+ function makeGraphQLQueryTypes(topLevelName, builder, json, queryString) {
333
+ const schema = new GQLSchemaFromJSON(json);
334
+ const query = new GQLQuery(schema, queryString);
335
+ const types = new Map();
336
+ for (const odn of query.queries) {
337
+ const queryName = odn.name ? odn.name.value : topLevelName;
338
+ if (types.has(queryName)) {
339
+ return quicktype_core_1.panic(`Duplicate query name ${queryName}`);
340
+ }
341
+ const dataType = query.makeType(builder, odn, queryName);
342
+ const dataOrNullType = builder.getUnionType(quicktype_core_1.emptyTypeAttributes, new Set([dataType, builder.getPrimitiveType("null")]));
343
+ const errorType = builder.getClassType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["error"]), new Set(["graphQLError"]), false)), collection_utils_1.mapFromObject({
344
+ message: builder.makeClassProperty(builder.getStringType(quicktype_core_1.emptyTypeAttributes, quicktype_core_1.StringTypes.unrestricted), false)
345
+ }));
346
+ const errorArray = builder.getArrayType(quicktype_core_1.namesTypeAttributeKind.makeAttributes(quicktype_core_1.TypeNames.make(new Set(["errors"]), new Set(["graphQLErrors"]), false)), errorType);
347
+ const t = builder.getClassType(quicktype_core_1.makeNamesTypeAttributes(queryName, false), collection_utils_1.mapFromObject({
348
+ data: builder.makeClassProperty(dataOrNullType, false),
349
+ errors: builder.makeClassProperty(errorArray, true)
350
+ }));
351
+ types.set(queryName, t);
352
+ }
353
+ return types;
354
+ }
355
+ class GraphQLInput {
356
+ constructor() {
357
+ this.kind = "graphql";
358
+ this.needIR = true;
359
+ this.needSchemaProcessing = false;
360
+ this._topLevels = new Map();
361
+ }
362
+ addSource(source) {
363
+ return __awaiter(this, void 0, void 0, function* () {
364
+ this.addSourceSync(source);
365
+ });
366
+ }
367
+ addSourceSync(source) {
368
+ this._topLevels.set(source.name, {
369
+ schema: source.schema,
370
+ query: source.query
371
+ });
372
+ }
373
+ singleStringSchemaSource() {
374
+ return undefined;
375
+ }
376
+ addTypes(ctx, typeBuilder) {
377
+ return __awaiter(this, void 0, void 0, function* () {
378
+ return this.addTypesSync(ctx, typeBuilder);
379
+ });
380
+ }
381
+ addTypesSync(_ctx, typeBuilder) {
382
+ for (const [name, { schema, query }] of this._topLevels) {
383
+ const newTopLevels = makeGraphQLQueryTypes(name, typeBuilder, schema, query);
384
+ for (const [actualName, t] of newTopLevels) {
385
+ typeBuilder.addTopLevel(this._topLevels.size === 1 ? name : actualName, t);
386
+ }
387
+ }
388
+ }
389
+ }
390
+ exports.GraphQLInput = GraphQLInput;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "quicktype-graphql-input",
3
- "version": "0.0.57",
3
+ "version": "0.0.58",
4
4
  "package": "Package for using GraphQL as an input language to quicktype",
5
5
  "license": "Apache-2.0",
6
6
  "main": "dist/index.js",
@@ -8,25 +8,25 @@
8
8
  "repository": "https://github.com/quicktype/quicktype",
9
9
  "scripts": {
10
10
  "clean": "rm -rf dist node_modules *~",
11
- "postpack": "npm run build",
11
+ "prepare": "npm run build",
12
12
  "build": "tsc",
13
13
  "tslint": "tslint --project ."
14
14
  },
15
15
  "dependencies": {
16
- "quicktype-core": "^7.0.33",
16
+ "quicktype-core": "^7.0.35",
17
17
  "collection-utils": "^1.0.1",
18
18
  "graphql": "^0.11.7"
19
19
  },
20
20
  "devDependencies": {
21
- "@types/node": "18.11.18",
21
+ "@types/node": "^8.10.10",
22
22
  "@types/graphql": "^0.11.7",
23
- "typescript": "4.9.4",
23
+ "typescript": "~3.2.1",
24
24
  "tslint": "^5.11.0"
25
25
  },
26
26
  "files": [
27
27
  "dist/**"
28
28
  ],
29
29
  "config": {
30
- "commit": "14e4080ab9a1d44c280b88a2d9f17b13a923ec0b"
30
+ "commit": "b3ef38043ae6a0dc6a64760f50c0a43cbba053b6"
31
31
  }
32
32
  }