@baeta/plugin-federation 0.0.0 → 2.0.0-next.13

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.
package/dist/index.js ADDED
@@ -0,0 +1,1827 @@
1
+ import fs from "node:fs/promises";
2
+ import { createPluginV1, getModuleExportName } from "@baeta/generator-sdk";
3
+ import { getSourcesFromSchema, loadSchema } from "@baeta/util-graphql";
4
+ import { GraphQLList, GraphQLNonNull, Kind, isEnumType, isInterfaceType, isObjectType, isScalarType, parse, print, visit } from "graphql";
5
+ import { relative } from "@baeta/util-path";
6
+ import { mergeTypeDefs } from "@graphql-tools/merge";
7
+ //#region lib/federation-info.ts
8
+ function buildFederationInfo(spec, sources) {
9
+ const specDirectiveNames = new Set(spec.directives.map((d) => d.name));
10
+ const usedDirectiveNames = /* @__PURE__ */ new Set();
11
+ const resolvableInterfacesMap = /* @__PURE__ */ new Map();
12
+ const resolvableEntitiesMap = /* @__PURE__ */ new Map();
13
+ for (const source of sources) {
14
+ if (!source.document) continue;
15
+ visit(source.document, {
16
+ Directive(node) {
17
+ const directiveName = `@${node.name.value}`;
18
+ if (specDirectiveNames.has(directiveName)) usedDirectiveNames.add(directiveName);
19
+ },
20
+ InterfaceTypeDefinition(node) {
21
+ addKeyDirectivesSelectionSetToMap(resolvableInterfacesMap, node.name.value, node.directives);
22
+ },
23
+ InterfaceTypeExtension(node) {
24
+ addKeyDirectivesSelectionSetToMap(resolvableInterfacesMap, node.name.value, node.directives);
25
+ }
26
+ });
27
+ }
28
+ for (const source of sources) {
29
+ if (!source.document) continue;
30
+ visit(source.document, {
31
+ ObjectTypeDefinition(node) {
32
+ addKeyDirectivesSelectionSetToMap(resolvableEntitiesMap, node.name.value, node.directives);
33
+ inheritInterfaceSelectionSets(resolvableInterfacesMap, resolvableEntitiesMap, node.name.value, node.interfaces);
34
+ },
35
+ ObjectTypeExtension(node) {
36
+ addKeyDirectivesSelectionSetToMap(resolvableEntitiesMap, node.name.value, node.directives);
37
+ inheritInterfaceSelectionSets(resolvableInterfacesMap, resolvableEntitiesMap, node.name.value, node.interfaces);
38
+ }
39
+ });
40
+ }
41
+ return {
42
+ usedDirectiveNames,
43
+ resolvableEntitiesMap
44
+ };
45
+ }
46
+ function inheritInterfaceSelectionSets(interfacesSelectionsMap, map, entityName, entityInterfaces = []) {
47
+ for (const iface of entityInterfaces) {
48
+ const ifaceName = iface.name.value;
49
+ const ifaceSelections = interfacesSelectionsMap.get(ifaceName);
50
+ if (!ifaceSelections) continue;
51
+ const existing = map.get(entityName) ?? /* @__PURE__ */ new Set();
52
+ for (const selectionSet of ifaceSelections) existing.add(selectionSet);
53
+ map.set(entityName, existing);
54
+ }
55
+ }
56
+ function addKeyDirectivesSelectionSetToMap(map, typeName, directives = []) {
57
+ for (const directive of directives) {
58
+ const selectionSet = getKeyDirectiveSelectionSet(directive);
59
+ if (!selectionSet) continue;
60
+ const existing = map.get(typeName) ?? /* @__PURE__ */ new Set();
61
+ existing.add(selectionSet);
62
+ map.set(typeName, existing);
63
+ }
64
+ }
65
+ function getKeyDirectiveSelectionSet(directive) {
66
+ if (directive.name.value !== "key") return null;
67
+ const fieldsArg = directive.arguments?.find((arg) => arg.name.value === "fields");
68
+ if (!fieldsArg) return null;
69
+ if (fieldsArg.value.kind !== Kind.STRING) return null;
70
+ const resolvableArg = directive.arguments?.find((arg) => arg.name.value === "resolvable");
71
+ if (resolvableArg && resolvableArg.value.kind === Kind.BOOLEAN && resolvableArg.value.value === false) return null;
72
+ return fieldsArg.value.value.trim().replaceAll(/\s+/g, "");
73
+ }
74
+ //#endregion
75
+ //#region lib/print-federation-types.ts
76
+ function printFederationTypes(schema, federationInfo, options) {
77
+ const entitiesRepresentations = [...federationInfo.resolvableEntitiesMap.entries()].map(([typeName, fields]) => buildRepresentationForType(schema, typeName, fields));
78
+ const entityHandlerTypes = [...federationInfo.resolvableEntitiesMap.keys()].map((typeName) => buildEntityHandlerTypeForType(typeName));
79
+ const entityRepresentationUnion = [...federationInfo.resolvableEntitiesMap.keys()].map((typeName) => `${typeName}EntityRepresentation`).join(" | ") || "never";
80
+ return [
81
+ `import type {Ctx, Info} from "${relative(options.typesDir, options.modulesDir)}/types${options.extension}";`,
82
+ `import * as Types from "./types${options.extension}";`,
83
+ "",
84
+ "type Result<T> = T | PromiseLike<T>;",
85
+ "",
86
+ entitiesRepresentations.join("\n\n"),
87
+ "",
88
+ entityHandlerTypes.join("\n\n"),
89
+ "",
90
+ `export type EntityRepresentation = ${entityRepresentationUnion};`,
91
+ "",
92
+ `export type EntityHandlerMap = { ${[...federationInfo.resolvableEntitiesMap.keys()].map((typeName) => `"${typeName}": ${typeName}EntityHandler`).join("; ")} };`
93
+ ].join("\n");
94
+ }
95
+ function buildEntityHandlerTypeForType(typeName) {
96
+ return `export type ${typeName}EntityHandler = (representation: ${typeName}EntityRepresentation, ctx: Ctx, info: Info) => Result<Types.${typeName} & {__typename: "${typeName}"} | null>`;
97
+ }
98
+ function buildRepresentationForType(schema, typeName, fields) {
99
+ const objectType = schema.getType(typeName);
100
+ if (!objectType || !isObjectType(objectType)) throw new Error(`Type "${typeName}" not found or is not an object type`);
101
+ return `export type ${typeName}EntityRepresentation = { __typename: "${typeName}" } & (${[...fields].map((fieldSet) => buildShape(objectType, fieldSet)).join(" | ")})`;
102
+ }
103
+ function buildShape(type, keyFields) {
104
+ const doc = parse(`{ ${keyFields} }`);
105
+ const selectionSet = doc.definitions[0].kind === Kind.OPERATION_DEFINITION ? doc.definitions[0].selectionSet : null;
106
+ if (!selectionSet) throw new Error("Invalid key fields");
107
+ return selectionSetToTS(selectionSet, type);
108
+ }
109
+ function selectionSetToTS(selectionSet, parentType) {
110
+ const fields = parentType.getFields();
111
+ const parts = [];
112
+ for (const selection of selectionSet.selections) {
113
+ if (selection.kind !== Kind.FIELD) continue;
114
+ const name = selection.name.value;
115
+ const field = fields[name];
116
+ if (!field) throw new Error(`Field "${name}" not found on ${parentType.name}`);
117
+ const naked = unwrap(field.type);
118
+ if (isScalarType(naked) || isEnumType(naked)) parts.push(`${name}: ${scalarToTS(naked.name)}`);
119
+ else if ((isObjectType(naked) || isInterfaceType(naked)) && selection.selectionSet) {
120
+ const nested = selectionSetToTS(selection.selectionSet, naked);
121
+ parts.push(`${name}: ${nested}`);
122
+ }
123
+ }
124
+ return `{ ${parts.join("; ")} }`;
125
+ }
126
+ function unwrap(type) {
127
+ if (type instanceof GraphQLNonNull || type instanceof GraphQLList) return unwrap(type.ofType);
128
+ return type;
129
+ }
130
+ function scalarToTS(name) {
131
+ return `Types.Scalars["${name}"]`;
132
+ }
133
+ //#endregion
134
+ //#region lib/print-handlers-starter.ts
135
+ function printHandlersStarter(options) {
136
+ return [
137
+ "/**",
138
+ "* Register your reference resolvers for federation entities in this file.",
139
+ "* This file is generated by Baeta, but it will not be overwritten once created,",
140
+ "* so it's safe to edit it directly.",
141
+ "*/",
142
+ "",
143
+ `import type { EntityHandlerMap } from "${relative(options.federationRootDir, options.typesDir)}/federation.ts";`,
144
+ "",
145
+ "const entityHandlersMap: EntityHandlerMap = {",
146
+ "",
147
+ "};",
148
+ "",
149
+ "export default entityHandlersMap;"
150
+ ].join("\n");
151
+ }
152
+ //#endregion
153
+ //#region lib/print-resolvers.ts
154
+ function printResolvers(spec, info, options) {
155
+ const moduleExportName = getModuleExportName(options.moduleName);
156
+ const imports = [
157
+ "import * as BaetaFederation from \"@baeta/federation\"",
158
+ `import type * as FederationTypes from "${relative(options.federationRootDir, options.typesDir)}/federation${options.extension}"`,
159
+ `import federationSDL from "./federation-sdl${options.extension}"`,
160
+ `import { ${moduleExportName} } from "./${options.moduleDefinitionName}${options.extension}"`,
161
+ info.resolvableEntitiesMap.size > 0 ? `import handlersMap from "./entity-handlers${options.extension}"` : null
162
+ ].filter((el) => el != null).join(";\n");
163
+ const scalarResolvers = getUniqueScalars(spec, options.includedDirectiveNames).map(printScalarResolver);
164
+ const moduleExportBody = [
165
+ printQueryTypeResolver(info, moduleExportName),
166
+ printServiceTypeResolver(moduleExportName),
167
+ printScalarResolver({
168
+ name: "_Any",
169
+ serialize: "json"
170
+ }),
171
+ ...scalarResolvers
172
+ ].map(ident(2)).join(",\n");
173
+ return [
174
+ imports,
175
+ "",
176
+ [
177
+ `export default ${moduleExportName}.$schema({`,
178
+ moduleExportBody,
179
+ "});"
180
+ ].join("\n")
181
+ ].join("\n");
182
+ }
183
+ function printScalarResolver(scalar) {
184
+ return `${scalar.name}: BaetaFederation.createFederationScalar('${scalar.serialize}', '${scalar.name}')`;
185
+ }
186
+ function printServiceTypeResolver(moduleExportName) {
187
+ return [
188
+ `_Service: ${moduleExportName}._Service.$fields({`,
189
+ ` sdl: ${moduleExportName}._Service.sdl.key('sdl'),`,
190
+ "})"
191
+ ].join("\n");
192
+ }
193
+ function printQueryTypeResolver(info, moduleExportName) {
194
+ return [
195
+ `Query: ${moduleExportName}.Query.$fields({`,
196
+ info.resolvableEntitiesMap.size > 0 ? printEntityFieldResolver(moduleExportName) : null,
197
+ ` _service: ${moduleExportName}.Query._service.resolve(() => {`,
198
+ " return { sdl: federationSDL };",
199
+ " }),",
200
+ "})"
201
+ ].filter((el) => el != null).join("\n");
202
+ }
203
+ function printEntityFieldResolver(moduleExportName) {
204
+ return [
205
+ `_entities: ${moduleExportName}.Query._entities.resolve((params) => {`,
206
+ " const representations = params.args.representations as FederationTypes.EntityRepresentation[];",
207
+ " return BaetaFederation.resolveEntities(representations, handlersMap satisfies FederationTypes.EntityHandlerMap, params.ctx, params.info);",
208
+ "}),"
209
+ ].map(ident(2)).join("\n");
210
+ }
211
+ function getUniqueScalars(spec, included) {
212
+ const seen = /* @__PURE__ */ new Set();
213
+ const scalars = [];
214
+ for (const directive of spec.directives) {
215
+ if (!included.has(directive.name)) continue;
216
+ if (!directive.scalars) continue;
217
+ for (const scalar of directive.scalars) {
218
+ if (seen.has(scalar.name)) continue;
219
+ seen.add(scalar.name);
220
+ scalars.push(scalar);
221
+ }
222
+ }
223
+ return scalars;
224
+ }
225
+ function ident(spaces) {
226
+ return (str) => {
227
+ const padding = " ".repeat(spaces);
228
+ return str.split("\n").map((line) => padding + line).join("\n");
229
+ };
230
+ }
231
+ //#endregion
232
+ //#region lib/print-schema-spec.ts
233
+ function printSchemaSpec(spec, include) {
234
+ const directives = spec.directives.filter((d) => include.has(d.name));
235
+ const scalars = pickUniqueScalars(directives);
236
+ return [
237
+ `# Federation Specification ${spec.version}`,
238
+ "",
239
+ ...directives.map(printDirective),
240
+ "",
241
+ ...scalars.map(printScalar),
242
+ scalars.length > 0 ? "" : null
243
+ ].filter((el) => el != null).join("\n");
244
+ }
245
+ function printDirective(directive) {
246
+ return [
247
+ `directive ${directive.name}${printArgs(directive.args)}`,
248
+ directive.locations.length > 0 && directive.repeatable ? "repeatable" : null,
249
+ directive.locations.length > 0 ? `on ${directive.locations.join(" | ")}` : null
250
+ ].filter((el) => el != null).join(" ");
251
+ }
252
+ function printArgs(args) {
253
+ if (!args || args.length === 0) return "";
254
+ return `(${args.map(printArg).join(", ")})`;
255
+ }
256
+ function printArg(arg) {
257
+ return `${arg.name}: ${arg.type}${printArgDefaultValue(arg.defaultValue)}`;
258
+ }
259
+ function printArgDefaultValue(value) {
260
+ if (value === void 0) return "";
261
+ if (typeof value === "string") return ` = ${JSON.stringify(value)}`;
262
+ return ` = ${value}`;
263
+ }
264
+ function printScalar(scalar) {
265
+ return `scalar ${scalar.name}`;
266
+ }
267
+ function pickUniqueScalars(directives) {
268
+ const seen = /* @__PURE__ */ new Set();
269
+ const uniqueScalars = [];
270
+ for (const directive of directives) for (const scalar of directive.scalars ?? []) if (!seen.has(scalar.name)) {
271
+ seen.add(scalar.name);
272
+ uniqueScalars.push(scalar);
273
+ }
274
+ return uniqueScalars;
275
+ }
276
+ //#endregion
277
+ //#region lib/print-schema-types.ts
278
+ function printSchemaTypes(federationInfo) {
279
+ const entities = [...federationInfo.resolvableEntitiesMap.keys()];
280
+ const queryType = [
281
+ "type Query {",
282
+ " _service: _Service!",
283
+ entities.length > 0 ? " _entities(representations: [_Any!]!): [_Entity]!" : null,
284
+ "}"
285
+ ].filter((el) => el != null).join("\n");
286
+ return [
287
+ "scalar _Any",
288
+ entities.length > 0 ? `union _Entity = ${entities.join(" | ")}` : "",
289
+ "type _Service { sdl: String! }",
290
+ queryType
291
+ ].filter((s) => s).join("\n\n");
292
+ }
293
+ //#endregion
294
+ //#region lib/print-sdl.ts
295
+ function printSDL(spec, sources, federationInfo) {
296
+ const importList = [...federationInfo.usedDirectiveNames].map((name) => `"${name}"`).join(", ");
297
+ const repeatableDirectives = new Set(spec.directives.filter((d) => d.repeatable).map((d) => d.name.replace("@", "")));
298
+ return `export default \`${[
299
+ "",
300
+ print(mergeTypeDefs([parse(`extend schema @link(url: "https://specs.apollo.dev/federation/v${spec.version}", import: [${importList}])`), ...sources.map((s) => s.document).filter((el) => el != null)], {
301
+ useSchemaDefinition: false,
302
+ repeatableLinkImports: repeatableDirectives
303
+ })),
304
+ ""
305
+ ].join("\n")}\`;`;
306
+ }
307
+ const federationSpecs = [
308
+ {
309
+ version: "2.0",
310
+ directives: [
311
+ {
312
+ name: "@key",
313
+ locations: ["OBJECT", "INTERFACE"],
314
+ args: [{
315
+ name: "fields",
316
+ type: "FieldSet!"
317
+ }, {
318
+ name: "resolvable",
319
+ type: "Boolean",
320
+ defaultValue: true
321
+ }],
322
+ repeatable: true,
323
+ scalars: [{
324
+ name: "FieldSet",
325
+ serialize: "string"
326
+ }]
327
+ },
328
+ {
329
+ name: "@requires",
330
+ locations: ["FIELD_DEFINITION"],
331
+ args: [{
332
+ name: "fields",
333
+ type: "FieldSet!"
334
+ }],
335
+ scalars: [{
336
+ name: "FieldSet",
337
+ serialize: "string"
338
+ }]
339
+ },
340
+ {
341
+ name: "@provides",
342
+ locations: ["FIELD_DEFINITION"],
343
+ args: [{
344
+ name: "fields",
345
+ type: "FieldSet!"
346
+ }],
347
+ scalars: [{
348
+ name: "FieldSet",
349
+ serialize: "string"
350
+ }]
351
+ },
352
+ {
353
+ name: "@external",
354
+ locations: ["OBJECT", "FIELD_DEFINITION"]
355
+ },
356
+ {
357
+ name: "@shareable",
358
+ locations: ["FIELD_DEFINITION", "OBJECT"]
359
+ },
360
+ {
361
+ name: "@extends",
362
+ locations: ["OBJECT", "INTERFACE"]
363
+ },
364
+ {
365
+ name: "@override",
366
+ locations: ["FIELD_DEFINITION"],
367
+ args: [{
368
+ name: "from",
369
+ type: "String!"
370
+ }]
371
+ },
372
+ {
373
+ name: "@inaccessible",
374
+ locations: [
375
+ "FIELD_DEFINITION",
376
+ "OBJECT",
377
+ "INTERFACE",
378
+ "UNION",
379
+ "ENUM",
380
+ "ENUM_VALUE",
381
+ "SCALAR",
382
+ "INPUT_OBJECT",
383
+ "INPUT_FIELD_DEFINITION",
384
+ "ARGUMENT_DEFINITION"
385
+ ]
386
+ },
387
+ {
388
+ name: "@tag",
389
+ locations: [
390
+ "FIELD_DEFINITION",
391
+ "INTERFACE",
392
+ "OBJECT",
393
+ "UNION",
394
+ "ARGUMENT_DEFINITION",
395
+ "SCALAR",
396
+ "ENUM",
397
+ "ENUM_VALUE",
398
+ "INPUT_OBJECT",
399
+ "INPUT_FIELD_DEFINITION"
400
+ ],
401
+ args: [{
402
+ name: "name",
403
+ type: "String!"
404
+ }],
405
+ repeatable: true
406
+ }
407
+ ]
408
+ },
409
+ {
410
+ version: "2.1",
411
+ directives: [
412
+ {
413
+ name: "@composeDirective",
414
+ locations: ["SCHEMA"],
415
+ args: [{
416
+ name: "name",
417
+ type: "String!"
418
+ }],
419
+ repeatable: true
420
+ },
421
+ {
422
+ name: "@extends",
423
+ locations: ["OBJECT", "INTERFACE"]
424
+ },
425
+ {
426
+ name: "@external",
427
+ locations: ["OBJECT", "FIELD_DEFINITION"]
428
+ },
429
+ {
430
+ name: "@key",
431
+ locations: ["OBJECT", "INTERFACE"],
432
+ args: [{
433
+ name: "fields",
434
+ type: "FieldSet!"
435
+ }, {
436
+ name: "resolvable",
437
+ type: "Boolean",
438
+ defaultValue: true
439
+ }],
440
+ repeatable: true,
441
+ scalars: [{
442
+ name: "FieldSet",
443
+ serialize: "string"
444
+ }]
445
+ },
446
+ {
447
+ name: "@inaccessible",
448
+ locations: [
449
+ "FIELD_DEFINITION",
450
+ "OBJECT",
451
+ "INTERFACE",
452
+ "UNION",
453
+ "ENUM",
454
+ "ENUM_VALUE",
455
+ "SCALAR",
456
+ "INPUT_OBJECT",
457
+ "INPUT_FIELD_DEFINITION",
458
+ "ARGUMENT_DEFINITION"
459
+ ]
460
+ },
461
+ {
462
+ name: "@override",
463
+ locations: ["FIELD_DEFINITION"],
464
+ args: [{
465
+ name: "from",
466
+ type: "String!"
467
+ }]
468
+ },
469
+ {
470
+ name: "@provides",
471
+ locations: ["FIELD_DEFINITION"],
472
+ args: [{
473
+ name: "fields",
474
+ type: "FieldSet!"
475
+ }],
476
+ scalars: [{
477
+ name: "FieldSet",
478
+ serialize: "string"
479
+ }]
480
+ },
481
+ {
482
+ name: "@requires",
483
+ locations: ["FIELD_DEFINITION"],
484
+ args: [{
485
+ name: "fields",
486
+ type: "FieldSet!"
487
+ }],
488
+ scalars: [{
489
+ name: "FieldSet",
490
+ serialize: "string"
491
+ }]
492
+ },
493
+ {
494
+ name: "@shareable",
495
+ locations: ["FIELD_DEFINITION", "OBJECT"]
496
+ },
497
+ {
498
+ name: "@tag",
499
+ locations: [
500
+ "FIELD_DEFINITION",
501
+ "INTERFACE",
502
+ "OBJECT",
503
+ "UNION",
504
+ "ARGUMENT_DEFINITION",
505
+ "SCALAR",
506
+ "ENUM",
507
+ "ENUM_VALUE",
508
+ "INPUT_OBJECT",
509
+ "INPUT_FIELD_DEFINITION"
510
+ ],
511
+ args: [{
512
+ name: "name",
513
+ type: "String!"
514
+ }],
515
+ repeatable: true
516
+ }
517
+ ]
518
+ },
519
+ {
520
+ version: "2.2",
521
+ directives: [
522
+ {
523
+ name: "@composeDirective",
524
+ locations: ["SCHEMA"],
525
+ args: [{
526
+ name: "name",
527
+ type: "String!"
528
+ }],
529
+ repeatable: true
530
+ },
531
+ {
532
+ name: "@extends",
533
+ locations: ["OBJECT", "INTERFACE"]
534
+ },
535
+ {
536
+ name: "@external",
537
+ locations: ["OBJECT", "FIELD_DEFINITION"]
538
+ },
539
+ {
540
+ name: "@key",
541
+ locations: ["OBJECT", "INTERFACE"],
542
+ args: [{
543
+ name: "fields",
544
+ type: "FieldSet!"
545
+ }, {
546
+ name: "resolvable",
547
+ type: "Boolean",
548
+ defaultValue: true
549
+ }],
550
+ repeatable: true,
551
+ scalars: [{
552
+ name: "FieldSet",
553
+ serialize: "string"
554
+ }]
555
+ },
556
+ {
557
+ name: "@inaccessible",
558
+ locations: [
559
+ "FIELD_DEFINITION",
560
+ "OBJECT",
561
+ "INTERFACE",
562
+ "UNION",
563
+ "ENUM",
564
+ "ENUM_VALUE",
565
+ "SCALAR",
566
+ "INPUT_OBJECT",
567
+ "INPUT_FIELD_DEFINITION",
568
+ "ARGUMENT_DEFINITION"
569
+ ]
570
+ },
571
+ {
572
+ name: "@override",
573
+ locations: ["FIELD_DEFINITION"],
574
+ args: [{
575
+ name: "from",
576
+ type: "String!"
577
+ }]
578
+ },
579
+ {
580
+ name: "@provides",
581
+ locations: ["FIELD_DEFINITION"],
582
+ args: [{
583
+ name: "fields",
584
+ type: "FieldSet!"
585
+ }],
586
+ scalars: [{
587
+ name: "FieldSet",
588
+ serialize: "string"
589
+ }]
590
+ },
591
+ {
592
+ name: "@requires",
593
+ locations: ["FIELD_DEFINITION"],
594
+ args: [{
595
+ name: "fields",
596
+ type: "FieldSet!"
597
+ }],
598
+ scalars: [{
599
+ name: "FieldSet",
600
+ serialize: "string"
601
+ }]
602
+ },
603
+ {
604
+ name: "@shareable",
605
+ locations: ["FIELD_DEFINITION", "OBJECT"],
606
+ repeatable: true
607
+ },
608
+ {
609
+ name: "@tag",
610
+ locations: [
611
+ "FIELD_DEFINITION",
612
+ "INTERFACE",
613
+ "OBJECT",
614
+ "UNION",
615
+ "ARGUMENT_DEFINITION",
616
+ "SCALAR",
617
+ "ENUM",
618
+ "ENUM_VALUE",
619
+ "INPUT_OBJECT",
620
+ "INPUT_FIELD_DEFINITION"
621
+ ],
622
+ args: [{
623
+ name: "name",
624
+ type: "String!"
625
+ }],
626
+ repeatable: true
627
+ }
628
+ ]
629
+ },
630
+ {
631
+ version: "2.3",
632
+ directives: [
633
+ {
634
+ name: "@composeDirective",
635
+ locations: ["SCHEMA"],
636
+ args: [{
637
+ name: "name",
638
+ type: "String!"
639
+ }],
640
+ repeatable: true
641
+ },
642
+ {
643
+ name: "@extends",
644
+ locations: ["OBJECT", "INTERFACE"]
645
+ },
646
+ {
647
+ name: "@external",
648
+ locations: ["OBJECT", "FIELD_DEFINITION"]
649
+ },
650
+ {
651
+ name: "@key",
652
+ locations: ["OBJECT", "INTERFACE"],
653
+ args: [{
654
+ name: "fields",
655
+ type: "FieldSet!"
656
+ }, {
657
+ name: "resolvable",
658
+ type: "Boolean",
659
+ defaultValue: true
660
+ }],
661
+ repeatable: true,
662
+ scalars: [{
663
+ name: "FieldSet",
664
+ serialize: "string"
665
+ }]
666
+ },
667
+ {
668
+ name: "@inaccessible",
669
+ locations: [
670
+ "FIELD_DEFINITION",
671
+ "OBJECT",
672
+ "INTERFACE",
673
+ "UNION",
674
+ "ENUM",
675
+ "ENUM_VALUE",
676
+ "SCALAR",
677
+ "INPUT_OBJECT",
678
+ "INPUT_FIELD_DEFINITION",
679
+ "ARGUMENT_DEFINITION"
680
+ ]
681
+ },
682
+ {
683
+ name: "@interfaceObject",
684
+ locations: ["OBJECT"]
685
+ },
686
+ {
687
+ name: "@override",
688
+ locations: ["FIELD_DEFINITION"],
689
+ args: [{
690
+ name: "from",
691
+ type: "String!"
692
+ }]
693
+ },
694
+ {
695
+ name: "@provides",
696
+ locations: ["FIELD_DEFINITION"],
697
+ args: [{
698
+ name: "fields",
699
+ type: "FieldSet!"
700
+ }],
701
+ scalars: [{
702
+ name: "FieldSet",
703
+ serialize: "string"
704
+ }]
705
+ },
706
+ {
707
+ name: "@requires",
708
+ locations: ["FIELD_DEFINITION"],
709
+ args: [{
710
+ name: "fields",
711
+ type: "FieldSet!"
712
+ }],
713
+ scalars: [{
714
+ name: "FieldSet",
715
+ serialize: "string"
716
+ }]
717
+ },
718
+ {
719
+ name: "@shareable",
720
+ locations: ["FIELD_DEFINITION", "OBJECT"],
721
+ repeatable: true
722
+ },
723
+ {
724
+ name: "@tag",
725
+ locations: [
726
+ "FIELD_DEFINITION",
727
+ "INTERFACE",
728
+ "OBJECT",
729
+ "UNION",
730
+ "ARGUMENT_DEFINITION",
731
+ "SCALAR",
732
+ "ENUM",
733
+ "ENUM_VALUE",
734
+ "INPUT_OBJECT",
735
+ "INPUT_FIELD_DEFINITION"
736
+ ],
737
+ args: [{
738
+ name: "name",
739
+ type: "String!"
740
+ }],
741
+ repeatable: true
742
+ }
743
+ ]
744
+ },
745
+ {
746
+ version: "2.4",
747
+ directives: [
748
+ {
749
+ name: "@composeDirective",
750
+ locations: ["SCHEMA"],
751
+ args: [{
752
+ name: "name",
753
+ type: "String!"
754
+ }],
755
+ repeatable: true
756
+ },
757
+ {
758
+ name: "@extends",
759
+ locations: ["OBJECT", "INTERFACE"]
760
+ },
761
+ {
762
+ name: "@external",
763
+ locations: ["OBJECT", "FIELD_DEFINITION"]
764
+ },
765
+ {
766
+ name: "@key",
767
+ locations: ["OBJECT", "INTERFACE"],
768
+ args: [{
769
+ name: "fields",
770
+ type: "FieldSet!"
771
+ }, {
772
+ name: "resolvable",
773
+ type: "Boolean",
774
+ defaultValue: true
775
+ }],
776
+ repeatable: true,
777
+ scalars: [{
778
+ name: "FieldSet",
779
+ serialize: "string"
780
+ }]
781
+ },
782
+ {
783
+ name: "@inaccessible",
784
+ locations: [
785
+ "FIELD_DEFINITION",
786
+ "OBJECT",
787
+ "INTERFACE",
788
+ "UNION",
789
+ "ENUM",
790
+ "ENUM_VALUE",
791
+ "SCALAR",
792
+ "INPUT_OBJECT",
793
+ "INPUT_FIELD_DEFINITION",
794
+ "ARGUMENT_DEFINITION"
795
+ ]
796
+ },
797
+ {
798
+ name: "@interfaceObject",
799
+ locations: ["OBJECT"]
800
+ },
801
+ {
802
+ name: "@override",
803
+ locations: ["FIELD_DEFINITION"],
804
+ args: [{
805
+ name: "from",
806
+ type: "String!"
807
+ }]
808
+ },
809
+ {
810
+ name: "@provides",
811
+ locations: ["FIELD_DEFINITION"],
812
+ args: [{
813
+ name: "fields",
814
+ type: "FieldSet!"
815
+ }],
816
+ scalars: [{
817
+ name: "FieldSet",
818
+ serialize: "string"
819
+ }]
820
+ },
821
+ {
822
+ name: "@requires",
823
+ locations: ["FIELD_DEFINITION"],
824
+ args: [{
825
+ name: "fields",
826
+ type: "FieldSet!"
827
+ }],
828
+ scalars: [{
829
+ name: "FieldSet",
830
+ serialize: "string"
831
+ }]
832
+ },
833
+ {
834
+ name: "@shareable",
835
+ locations: ["FIELD_DEFINITION", "OBJECT"],
836
+ repeatable: true
837
+ },
838
+ {
839
+ name: "@tag",
840
+ locations: [
841
+ "FIELD_DEFINITION",
842
+ "INTERFACE",
843
+ "OBJECT",
844
+ "UNION",
845
+ "ARGUMENT_DEFINITION",
846
+ "SCALAR",
847
+ "ENUM",
848
+ "ENUM_VALUE",
849
+ "INPUT_OBJECT",
850
+ "INPUT_FIELD_DEFINITION"
851
+ ],
852
+ args: [{
853
+ name: "name",
854
+ type: "String!"
855
+ }],
856
+ repeatable: true
857
+ }
858
+ ]
859
+ },
860
+ {
861
+ version: "2.5",
862
+ directives: [
863
+ {
864
+ name: "@authenticated",
865
+ locations: [
866
+ "ENUM",
867
+ "FIELD_DEFINITION",
868
+ "INTERFACE",
869
+ "OBJECT",
870
+ "SCALAR"
871
+ ]
872
+ },
873
+ {
874
+ name: "@composeDirective",
875
+ locations: ["SCHEMA"],
876
+ args: [{
877
+ name: "name",
878
+ type: "String!"
879
+ }],
880
+ repeatable: true
881
+ },
882
+ {
883
+ name: "@extends",
884
+ locations: ["OBJECT", "INTERFACE"]
885
+ },
886
+ {
887
+ name: "@external",
888
+ locations: ["OBJECT", "FIELD_DEFINITION"]
889
+ },
890
+ {
891
+ name: "@key",
892
+ locations: ["OBJECT", "INTERFACE"],
893
+ args: [{
894
+ name: "fields",
895
+ type: "FieldSet!"
896
+ }, {
897
+ name: "resolvable",
898
+ type: "Boolean",
899
+ defaultValue: true
900
+ }],
901
+ repeatable: true,
902
+ scalars: [{
903
+ name: "FieldSet",
904
+ serialize: "string"
905
+ }]
906
+ },
907
+ {
908
+ name: "@inaccessible",
909
+ locations: [
910
+ "FIELD_DEFINITION",
911
+ "OBJECT",
912
+ "INTERFACE",
913
+ "UNION",
914
+ "ENUM",
915
+ "ENUM_VALUE",
916
+ "SCALAR",
917
+ "INPUT_OBJECT",
918
+ "INPUT_FIELD_DEFINITION",
919
+ "ARGUMENT_DEFINITION"
920
+ ]
921
+ },
922
+ {
923
+ name: "@interfaceObject",
924
+ locations: ["OBJECT"]
925
+ },
926
+ {
927
+ name: "@override",
928
+ locations: ["FIELD_DEFINITION"],
929
+ args: [{
930
+ name: "from",
931
+ type: "String!"
932
+ }]
933
+ },
934
+ {
935
+ name: "@provides",
936
+ locations: ["FIELD_DEFINITION"],
937
+ args: [{
938
+ name: "fields",
939
+ type: "FieldSet!"
940
+ }],
941
+ scalars: [{
942
+ name: "FieldSet",
943
+ serialize: "string"
944
+ }]
945
+ },
946
+ {
947
+ name: "@requires",
948
+ locations: ["FIELD_DEFINITION"],
949
+ args: [{
950
+ name: "fields",
951
+ type: "FieldSet!"
952
+ }],
953
+ scalars: [{
954
+ name: "FieldSet",
955
+ serialize: "string"
956
+ }]
957
+ },
958
+ {
959
+ name: "@requiresScopes",
960
+ locations: [
961
+ "ENUM",
962
+ "FIELD_DEFINITION",
963
+ "INTERFACE",
964
+ "OBJECT",
965
+ "SCALAR"
966
+ ],
967
+ args: [{
968
+ name: "scopes",
969
+ type: "[[Scope!]!]!"
970
+ }],
971
+ scalars: [{
972
+ name: "Scope",
973
+ serialize: "string"
974
+ }]
975
+ },
976
+ {
977
+ name: "@shareable",
978
+ locations: ["FIELD_DEFINITION", "OBJECT"],
979
+ repeatable: true
980
+ },
981
+ {
982
+ name: "@tag",
983
+ locations: [
984
+ "FIELD_DEFINITION",
985
+ "INTERFACE",
986
+ "OBJECT",
987
+ "UNION",
988
+ "ARGUMENT_DEFINITION",
989
+ "SCALAR",
990
+ "ENUM",
991
+ "ENUM_VALUE",
992
+ "INPUT_OBJECT",
993
+ "INPUT_FIELD_DEFINITION"
994
+ ],
995
+ args: [{
996
+ name: "name",
997
+ type: "String!"
998
+ }],
999
+ repeatable: true
1000
+ }
1001
+ ]
1002
+ },
1003
+ {
1004
+ version: "2.6",
1005
+ directives: [
1006
+ {
1007
+ name: "@authenticated",
1008
+ locations: [
1009
+ "ENUM",
1010
+ "FIELD_DEFINITION",
1011
+ "INTERFACE",
1012
+ "OBJECT",
1013
+ "SCALAR"
1014
+ ]
1015
+ },
1016
+ {
1017
+ name: "@composeDirective",
1018
+ locations: ["SCHEMA"],
1019
+ args: [{
1020
+ name: "name",
1021
+ type: "String!"
1022
+ }],
1023
+ repeatable: true
1024
+ },
1025
+ {
1026
+ name: "@extends",
1027
+ locations: ["OBJECT", "INTERFACE"]
1028
+ },
1029
+ {
1030
+ name: "@external",
1031
+ locations: ["OBJECT", "FIELD_DEFINITION"]
1032
+ },
1033
+ {
1034
+ name: "@key",
1035
+ locations: ["OBJECT", "INTERFACE"],
1036
+ args: [{
1037
+ name: "fields",
1038
+ type: "FieldSet!"
1039
+ }, {
1040
+ name: "resolvable",
1041
+ type: "Boolean",
1042
+ defaultValue: true
1043
+ }],
1044
+ repeatable: true,
1045
+ scalars: [{
1046
+ name: "FieldSet",
1047
+ serialize: "string"
1048
+ }]
1049
+ },
1050
+ {
1051
+ name: "@inaccessible",
1052
+ locations: [
1053
+ "FIELD_DEFINITION",
1054
+ "OBJECT",
1055
+ "INTERFACE",
1056
+ "UNION",
1057
+ "ENUM",
1058
+ "ENUM_VALUE",
1059
+ "SCALAR",
1060
+ "INPUT_OBJECT",
1061
+ "INPUT_FIELD_DEFINITION",
1062
+ "ARGUMENT_DEFINITION"
1063
+ ]
1064
+ },
1065
+ {
1066
+ name: "@interfaceObject",
1067
+ locations: ["OBJECT"]
1068
+ },
1069
+ {
1070
+ name: "@override",
1071
+ locations: ["FIELD_DEFINITION"],
1072
+ args: [{
1073
+ name: "from",
1074
+ type: "String!"
1075
+ }]
1076
+ },
1077
+ {
1078
+ name: "@policy",
1079
+ locations: [
1080
+ "ENUM",
1081
+ "FIELD_DEFINITION",
1082
+ "INTERFACE",
1083
+ "OBJECT",
1084
+ "SCALAR"
1085
+ ],
1086
+ args: [{
1087
+ name: "policies",
1088
+ type: "[[Policy!]!]!"
1089
+ }],
1090
+ scalars: [{
1091
+ name: "Policy",
1092
+ serialize: "string"
1093
+ }]
1094
+ },
1095
+ {
1096
+ name: "@provides",
1097
+ locations: ["FIELD_DEFINITION"],
1098
+ args: [{
1099
+ name: "fields",
1100
+ type: "FieldSet!"
1101
+ }],
1102
+ scalars: [{
1103
+ name: "FieldSet",
1104
+ serialize: "string"
1105
+ }]
1106
+ },
1107
+ {
1108
+ name: "@requires",
1109
+ locations: ["FIELD_DEFINITION"],
1110
+ args: [{
1111
+ name: "fields",
1112
+ type: "FieldSet!"
1113
+ }],
1114
+ scalars: [{
1115
+ name: "FieldSet",
1116
+ serialize: "string"
1117
+ }]
1118
+ },
1119
+ {
1120
+ name: "@requiresScopes",
1121
+ locations: [
1122
+ "ENUM",
1123
+ "FIELD_DEFINITION",
1124
+ "INTERFACE",
1125
+ "OBJECT",
1126
+ "SCALAR"
1127
+ ],
1128
+ args: [{
1129
+ name: "scopes",
1130
+ type: "[[Scope!]!]!"
1131
+ }],
1132
+ scalars: [{
1133
+ name: "Scope",
1134
+ serialize: "string"
1135
+ }]
1136
+ },
1137
+ {
1138
+ name: "@shareable",
1139
+ locations: ["FIELD_DEFINITION", "OBJECT"],
1140
+ repeatable: true
1141
+ },
1142
+ {
1143
+ name: "@tag",
1144
+ locations: [
1145
+ "FIELD_DEFINITION",
1146
+ "INTERFACE",
1147
+ "OBJECT",
1148
+ "UNION",
1149
+ "ARGUMENT_DEFINITION",
1150
+ "SCALAR",
1151
+ "ENUM",
1152
+ "ENUM_VALUE",
1153
+ "INPUT_OBJECT",
1154
+ "INPUT_FIELD_DEFINITION"
1155
+ ],
1156
+ args: [{
1157
+ name: "name",
1158
+ type: "String!"
1159
+ }],
1160
+ repeatable: true
1161
+ }
1162
+ ]
1163
+ },
1164
+ {
1165
+ version: "2.7",
1166
+ directives: [
1167
+ {
1168
+ name: "@authenticated",
1169
+ locations: [
1170
+ "ENUM",
1171
+ "FIELD_DEFINITION",
1172
+ "INTERFACE",
1173
+ "OBJECT",
1174
+ "SCALAR"
1175
+ ]
1176
+ },
1177
+ {
1178
+ name: "@composeDirective",
1179
+ locations: ["SCHEMA"],
1180
+ args: [{
1181
+ name: "name",
1182
+ type: "String!"
1183
+ }],
1184
+ repeatable: true
1185
+ },
1186
+ {
1187
+ name: "@extends",
1188
+ locations: ["OBJECT", "INTERFACE"]
1189
+ },
1190
+ {
1191
+ name: "@external",
1192
+ locations: ["OBJECT", "FIELD_DEFINITION"]
1193
+ },
1194
+ {
1195
+ name: "@key",
1196
+ locations: ["OBJECT", "INTERFACE"],
1197
+ args: [{
1198
+ name: "fields",
1199
+ type: "FieldSet!"
1200
+ }, {
1201
+ name: "resolvable",
1202
+ type: "Boolean",
1203
+ defaultValue: true
1204
+ }],
1205
+ repeatable: true,
1206
+ scalars: [{
1207
+ name: "FieldSet",
1208
+ serialize: "string"
1209
+ }]
1210
+ },
1211
+ {
1212
+ name: "@inaccessible",
1213
+ locations: [
1214
+ "FIELD_DEFINITION",
1215
+ "OBJECT",
1216
+ "INTERFACE",
1217
+ "UNION",
1218
+ "ENUM",
1219
+ "ENUM_VALUE",
1220
+ "SCALAR",
1221
+ "INPUT_OBJECT",
1222
+ "INPUT_FIELD_DEFINITION",
1223
+ "ARGUMENT_DEFINITION"
1224
+ ]
1225
+ },
1226
+ {
1227
+ name: "@interfaceObject",
1228
+ locations: ["OBJECT"]
1229
+ },
1230
+ {
1231
+ name: "@override",
1232
+ locations: ["FIELD_DEFINITION"],
1233
+ args: [{
1234
+ name: "from",
1235
+ type: "String!"
1236
+ }, {
1237
+ name: "label",
1238
+ type: "String"
1239
+ }]
1240
+ },
1241
+ {
1242
+ name: "@policy",
1243
+ locations: [
1244
+ "ENUM",
1245
+ "FIELD_DEFINITION",
1246
+ "INTERFACE",
1247
+ "OBJECT",
1248
+ "SCALAR"
1249
+ ],
1250
+ args: [{
1251
+ name: "policies",
1252
+ type: "[[Policy!]!]!"
1253
+ }],
1254
+ scalars: [{
1255
+ name: "Policy",
1256
+ serialize: "string"
1257
+ }]
1258
+ },
1259
+ {
1260
+ name: "@provides",
1261
+ locations: ["FIELD_DEFINITION"],
1262
+ args: [{
1263
+ name: "fields",
1264
+ type: "FieldSet!"
1265
+ }],
1266
+ scalars: [{
1267
+ name: "FieldSet",
1268
+ serialize: "string"
1269
+ }]
1270
+ },
1271
+ {
1272
+ name: "@requires",
1273
+ locations: ["FIELD_DEFINITION"],
1274
+ args: [{
1275
+ name: "fields",
1276
+ type: "FieldSet!"
1277
+ }],
1278
+ scalars: [{
1279
+ name: "FieldSet",
1280
+ serialize: "string"
1281
+ }]
1282
+ },
1283
+ {
1284
+ name: "@requiresScopes",
1285
+ locations: [
1286
+ "ENUM",
1287
+ "FIELD_DEFINITION",
1288
+ "INTERFACE",
1289
+ "OBJECT",
1290
+ "SCALAR"
1291
+ ],
1292
+ args: [{
1293
+ name: "scopes",
1294
+ type: "[[Scope!]!]!"
1295
+ }],
1296
+ scalars: [{
1297
+ name: "Scope",
1298
+ serialize: "string"
1299
+ }]
1300
+ },
1301
+ {
1302
+ name: "@shareable",
1303
+ locations: ["FIELD_DEFINITION", "OBJECT"],
1304
+ repeatable: true
1305
+ },
1306
+ {
1307
+ name: "@tag",
1308
+ locations: [
1309
+ "FIELD_DEFINITION",
1310
+ "INTERFACE",
1311
+ "OBJECT",
1312
+ "UNION",
1313
+ "ARGUMENT_DEFINITION",
1314
+ "SCALAR",
1315
+ "ENUM",
1316
+ "ENUM_VALUE",
1317
+ "INPUT_OBJECT",
1318
+ "INPUT_FIELD_DEFINITION"
1319
+ ],
1320
+ args: [{
1321
+ name: "name",
1322
+ type: "String!"
1323
+ }],
1324
+ repeatable: true
1325
+ }
1326
+ ]
1327
+ },
1328
+ {
1329
+ version: "2.8",
1330
+ directives: [
1331
+ {
1332
+ name: "@authenticated",
1333
+ locations: [
1334
+ "ENUM",
1335
+ "FIELD_DEFINITION",
1336
+ "INTERFACE",
1337
+ "OBJECT",
1338
+ "SCALAR"
1339
+ ]
1340
+ },
1341
+ {
1342
+ name: "@composeDirective",
1343
+ locations: ["SCHEMA"],
1344
+ args: [{
1345
+ name: "name",
1346
+ type: "String!"
1347
+ }],
1348
+ repeatable: true
1349
+ },
1350
+ {
1351
+ name: "@context",
1352
+ locations: [
1353
+ "OBJECT",
1354
+ "INTERFACE",
1355
+ "UNION"
1356
+ ],
1357
+ args: [{
1358
+ name: "name",
1359
+ type: "String!"
1360
+ }]
1361
+ },
1362
+ {
1363
+ name: "@extends",
1364
+ locations: ["OBJECT", "INTERFACE"]
1365
+ },
1366
+ {
1367
+ name: "@external",
1368
+ locations: ["OBJECT", "FIELD_DEFINITION"]
1369
+ },
1370
+ {
1371
+ name: "@fromContext",
1372
+ locations: ["ARGUMENT_DEFINITION"],
1373
+ args: [{
1374
+ name: "field",
1375
+ type: "ContextFieldValue"
1376
+ }],
1377
+ scalars: [{
1378
+ name: "ContextFieldValue",
1379
+ serialize: "string"
1380
+ }]
1381
+ },
1382
+ {
1383
+ name: "@key",
1384
+ locations: ["OBJECT", "INTERFACE"],
1385
+ args: [{
1386
+ name: "fields",
1387
+ type: "FieldSet!"
1388
+ }, {
1389
+ name: "resolvable",
1390
+ type: "Boolean",
1391
+ defaultValue: true
1392
+ }],
1393
+ repeatable: true,
1394
+ scalars: [{
1395
+ name: "FieldSet",
1396
+ serialize: "string"
1397
+ }]
1398
+ },
1399
+ {
1400
+ name: "@inaccessible",
1401
+ locations: [
1402
+ "FIELD_DEFINITION",
1403
+ "OBJECT",
1404
+ "INTERFACE",
1405
+ "UNION",
1406
+ "ENUM",
1407
+ "ENUM_VALUE",
1408
+ "SCALAR",
1409
+ "INPUT_OBJECT",
1410
+ "INPUT_FIELD_DEFINITION",
1411
+ "ARGUMENT_DEFINITION"
1412
+ ]
1413
+ },
1414
+ {
1415
+ name: "@interfaceObject",
1416
+ locations: ["OBJECT"]
1417
+ },
1418
+ {
1419
+ name: "@override",
1420
+ locations: ["FIELD_DEFINITION"],
1421
+ args: [{
1422
+ name: "from",
1423
+ type: "String!"
1424
+ }, {
1425
+ name: "label",
1426
+ type: "String"
1427
+ }]
1428
+ },
1429
+ {
1430
+ name: "@policy",
1431
+ locations: [
1432
+ "ENUM",
1433
+ "FIELD_DEFINITION",
1434
+ "INTERFACE",
1435
+ "OBJECT",
1436
+ "SCALAR"
1437
+ ],
1438
+ args: [{
1439
+ name: "policies",
1440
+ type: "[[Policy!]!]!"
1441
+ }],
1442
+ scalars: [{
1443
+ name: "Policy",
1444
+ serialize: "string"
1445
+ }]
1446
+ },
1447
+ {
1448
+ name: "@provides",
1449
+ locations: ["FIELD_DEFINITION"],
1450
+ args: [{
1451
+ name: "fields",
1452
+ type: "FieldSet!"
1453
+ }],
1454
+ scalars: [{
1455
+ name: "FieldSet",
1456
+ serialize: "string"
1457
+ }]
1458
+ },
1459
+ {
1460
+ name: "@requires",
1461
+ locations: ["FIELD_DEFINITION"],
1462
+ args: [{
1463
+ name: "fields",
1464
+ type: "FieldSet!"
1465
+ }],
1466
+ scalars: [{
1467
+ name: "FieldSet",
1468
+ serialize: "string"
1469
+ }]
1470
+ },
1471
+ {
1472
+ name: "@requiresScopes",
1473
+ locations: [
1474
+ "ENUM",
1475
+ "FIELD_DEFINITION",
1476
+ "INTERFACE",
1477
+ "OBJECT",
1478
+ "SCALAR"
1479
+ ],
1480
+ args: [{
1481
+ name: "scopes",
1482
+ type: "[[Scope!]!]!"
1483
+ }],
1484
+ scalars: [{
1485
+ name: "Scope",
1486
+ serialize: "string"
1487
+ }]
1488
+ },
1489
+ {
1490
+ name: "@shareable",
1491
+ locations: ["FIELD_DEFINITION", "OBJECT"],
1492
+ repeatable: true
1493
+ },
1494
+ {
1495
+ name: "@tag",
1496
+ locations: [
1497
+ "FIELD_DEFINITION",
1498
+ "INTERFACE",
1499
+ "OBJECT",
1500
+ "UNION",
1501
+ "ARGUMENT_DEFINITION",
1502
+ "SCALAR",
1503
+ "ENUM",
1504
+ "ENUM_VALUE",
1505
+ "INPUT_OBJECT",
1506
+ "INPUT_FIELD_DEFINITION"
1507
+ ],
1508
+ args: [{
1509
+ name: "name",
1510
+ type: "String!"
1511
+ }],
1512
+ repeatable: true
1513
+ }
1514
+ ]
1515
+ },
1516
+ {
1517
+ version: "2.9",
1518
+ directives: [
1519
+ {
1520
+ name: "@authenticated",
1521
+ locations: [
1522
+ "ENUM",
1523
+ "FIELD_DEFINITION",
1524
+ "INTERFACE",
1525
+ "OBJECT",
1526
+ "SCALAR"
1527
+ ]
1528
+ },
1529
+ {
1530
+ name: "@composeDirective",
1531
+ locations: ["SCHEMA"],
1532
+ args: [{
1533
+ name: "name",
1534
+ type: "String!"
1535
+ }],
1536
+ repeatable: true
1537
+ },
1538
+ {
1539
+ name: "@context",
1540
+ locations: [
1541
+ "OBJECT",
1542
+ "INTERFACE",
1543
+ "UNION"
1544
+ ],
1545
+ args: [{
1546
+ name: "name",
1547
+ type: "String!"
1548
+ }]
1549
+ },
1550
+ {
1551
+ name: "@cost",
1552
+ locations: [
1553
+ "ARGUMENT_DEFINITION",
1554
+ "ENUM",
1555
+ "FIELD_DEFINITION",
1556
+ "INPUT_FIELD_DEFINITION",
1557
+ "OBJECT",
1558
+ "SCALAR"
1559
+ ],
1560
+ args: [{
1561
+ name: "weight",
1562
+ type: "Int!"
1563
+ }]
1564
+ },
1565
+ {
1566
+ name: "@extends",
1567
+ locations: ["OBJECT", "INTERFACE"]
1568
+ },
1569
+ {
1570
+ name: "@external",
1571
+ locations: ["OBJECT", "FIELD_DEFINITION"]
1572
+ },
1573
+ {
1574
+ name: "@fromContext",
1575
+ locations: ["ARGUMENT_DEFINITION"],
1576
+ args: [{
1577
+ name: "field",
1578
+ type: "ContextFieldValue"
1579
+ }],
1580
+ scalars: [{
1581
+ name: "ContextFieldValue",
1582
+ serialize: "string"
1583
+ }]
1584
+ },
1585
+ {
1586
+ name: "@key",
1587
+ locations: ["OBJECT", "INTERFACE"],
1588
+ args: [{
1589
+ name: "fields",
1590
+ type: "FieldSet!"
1591
+ }, {
1592
+ name: "resolvable",
1593
+ type: "Boolean",
1594
+ defaultValue: true
1595
+ }],
1596
+ repeatable: true,
1597
+ scalars: [{
1598
+ name: "FieldSet",
1599
+ serialize: "string"
1600
+ }]
1601
+ },
1602
+ {
1603
+ name: "@inaccessible",
1604
+ locations: [
1605
+ "FIELD_DEFINITION",
1606
+ "OBJECT",
1607
+ "INTERFACE",
1608
+ "UNION",
1609
+ "ENUM",
1610
+ "ENUM_VALUE",
1611
+ "SCALAR",
1612
+ "INPUT_OBJECT",
1613
+ "INPUT_FIELD_DEFINITION",
1614
+ "ARGUMENT_DEFINITION"
1615
+ ]
1616
+ },
1617
+ {
1618
+ name: "@interfaceObject",
1619
+ locations: ["OBJECT"]
1620
+ },
1621
+ {
1622
+ name: "@listSize",
1623
+ locations: ["FIELD_DEFINITION"],
1624
+ args: [
1625
+ {
1626
+ name: "assumedSize",
1627
+ type: "Int"
1628
+ },
1629
+ {
1630
+ name: "slicingArguments",
1631
+ type: "[String!]"
1632
+ },
1633
+ {
1634
+ name: "sizedFields",
1635
+ type: "[String!]"
1636
+ },
1637
+ {
1638
+ name: "requireOneSlicingArgument",
1639
+ type: "Boolean",
1640
+ defaultValue: true
1641
+ }
1642
+ ]
1643
+ },
1644
+ {
1645
+ name: "@override",
1646
+ locations: ["FIELD_DEFINITION"],
1647
+ args: [{
1648
+ name: "from",
1649
+ type: "String!"
1650
+ }, {
1651
+ name: "label",
1652
+ type: "String"
1653
+ }]
1654
+ },
1655
+ {
1656
+ name: "@policy",
1657
+ locations: [
1658
+ "ENUM",
1659
+ "FIELD_DEFINITION",
1660
+ "INTERFACE",
1661
+ "OBJECT",
1662
+ "SCALAR"
1663
+ ],
1664
+ args: [{
1665
+ name: "policies",
1666
+ type: "[[Policy!]!]!"
1667
+ }],
1668
+ scalars: [{
1669
+ name: "Policy",
1670
+ serialize: "string"
1671
+ }]
1672
+ },
1673
+ {
1674
+ name: "@provides",
1675
+ locations: ["FIELD_DEFINITION"],
1676
+ args: [{
1677
+ name: "fields",
1678
+ type: "FieldSet!"
1679
+ }],
1680
+ scalars: [{
1681
+ name: "FieldSet",
1682
+ serialize: "string"
1683
+ }]
1684
+ },
1685
+ {
1686
+ name: "@requires",
1687
+ locations: ["FIELD_DEFINITION"],
1688
+ args: [{
1689
+ name: "fields",
1690
+ type: "FieldSet!"
1691
+ }],
1692
+ scalars: [{
1693
+ name: "FieldSet",
1694
+ serialize: "string"
1695
+ }]
1696
+ },
1697
+ {
1698
+ name: "@requiresScopes",
1699
+ locations: [
1700
+ "ENUM",
1701
+ "FIELD_DEFINITION",
1702
+ "INTERFACE",
1703
+ "OBJECT",
1704
+ "SCALAR"
1705
+ ],
1706
+ args: [{
1707
+ name: "scopes",
1708
+ type: "[[Scope!]!]!"
1709
+ }],
1710
+ scalars: [{
1711
+ name: "Scope",
1712
+ serialize: "string"
1713
+ }]
1714
+ },
1715
+ {
1716
+ name: "@shareable",
1717
+ locations: ["FIELD_DEFINITION", "OBJECT"],
1718
+ repeatable: true
1719
+ },
1720
+ {
1721
+ name: "@tag",
1722
+ locations: [
1723
+ "FIELD_DEFINITION",
1724
+ "INTERFACE",
1725
+ "OBJECT",
1726
+ "UNION",
1727
+ "ARGUMENT_DEFINITION",
1728
+ "SCALAR",
1729
+ "ENUM",
1730
+ "ENUM_VALUE",
1731
+ "INPUT_OBJECT",
1732
+ "INPUT_FIELD_DEFINITION"
1733
+ ],
1734
+ args: [{
1735
+ name: "name",
1736
+ type: "String!"
1737
+ }],
1738
+ repeatable: true
1739
+ }
1740
+ ]
1741
+ }
1742
+ ];
1743
+ //#endregion
1744
+ //#region lib/specs.ts
1745
+ function findSpecification(version) {
1746
+ const spec = federationSpecs.find((s) => s.version === version);
1747
+ if (!spec) throw new Error(`Unsupported federation version: ${version}`);
1748
+ return spec;
1749
+ }
1750
+ //#endregion
1751
+ //#region index.ts
1752
+ const DEFAULT_MODULE_NAME = "baeta-federation";
1753
+ const DEFAULT_VERSION = "2.9";
1754
+ const DEFAULT_DIRECTIVES = [
1755
+ "@key",
1756
+ "@external",
1757
+ "@requires",
1758
+ "@provides",
1759
+ "@extends"
1760
+ ];
1761
+ function federationPlugin(options) {
1762
+ return createPluginV1({
1763
+ name: "graphql",
1764
+ actionName: "GraphQL federation",
1765
+ watch: (generatorOptions, watcher) => {
1766
+ const federationRootDir = getModuleRootDir(generatorOptions.modulesDir, options);
1767
+ watcher.ignore(`${federationRootDir}/*.gql`);
1768
+ },
1769
+ generate: async (ctx, next) => {
1770
+ const moduleName = options?.moduleName ?? DEFAULT_MODULE_NAME;
1771
+ const specification = findSpecification(options?.version ?? DEFAULT_VERSION);
1772
+ const directiveNames = buildDirectiveNames(specification, options?.include);
1773
+ const federationRootDir = getModuleRootDir(ctx.generatorOptions.modulesDir, options);
1774
+ const federationTypesFilePath = `${ctx.generatorOptions.typesDir}/federation.ts`;
1775
+ const sdlFilePath = `${federationRootDir}/federation-sdl.ts`;
1776
+ const schemaSpecFilePath = `${federationRootDir}/federation-spec.gql`;
1777
+ const schemaTypesFilePath = `${federationRootDir}/federation-types.gql`;
1778
+ const entityHandlersFilePath = `${federationRootDir}/entity-handlers.ts`;
1779
+ const resolversFilePath = `${federationRootDir}/index.ts`;
1780
+ const schemaSpecFile = ctx.fileManager.createAndAdd(schemaSpecFilePath, printSchemaSpec(specification, directiveNames), "federation");
1781
+ await Promise.all([await schemaSpecFile.write(), fs.unlink(schemaTypesFilePath).catch(() => {})]);
1782
+ const { outputSchemaAst } = await loadSchema(ctx.generatorOptions.schemas, ctx.generatorOptions.cwd, ctx.generatorOptions.loaders);
1783
+ const sources = getSourcesFromSchema(outputSchemaAst).filter((source) => {
1784
+ return source.location !== schemaSpecFilePath && source.location !== schemaTypesFilePath;
1785
+ });
1786
+ const federationInfo = buildFederationInfo(specification, sources);
1787
+ ctx.fileManager.createAndAdd(sdlFilePath, printSDL(specification, sources, federationInfo), "federation");
1788
+ ctx.fileManager.createAndAdd(federationTypesFilePath, printFederationTypes(outputSchemaAst, federationInfo, {
1789
+ extension: ctx.generatorOptions.importExtension,
1790
+ modulesDir: ctx.generatorOptions.modulesDir,
1791
+ typesDir: ctx.generatorOptions.typesDir
1792
+ }), "federation");
1793
+ ctx.fileManager.createAndAdd(resolversFilePath, printResolvers(specification, federationInfo, {
1794
+ moduleName,
1795
+ typesDir: ctx.generatorOptions.typesDir,
1796
+ federationRootDir,
1797
+ extension: ctx.generatorOptions.importExtension,
1798
+ moduleDefinitionName: ctx.generatorOptions.moduleDefinitionName,
1799
+ includedDirectiveNames: directiveNames
1800
+ }), "federation");
1801
+ ctx.fileManager.createAndAdd(entityHandlersFilePath, printHandlersStarter({
1802
+ typesDir: ctx.generatorOptions.typesDir,
1803
+ federationRootDir,
1804
+ extension: ctx.generatorOptions.importExtension
1805
+ }), "federation", {
1806
+ disableOverwrite: true,
1807
+ disableBiomeV1Header: true,
1808
+ disableBiomeV2Header: true,
1809
+ disableEslintHeader: true,
1810
+ disableGenerationNoticeHeader: true
1811
+ });
1812
+ await ctx.fileManager.createAndAdd(schemaTypesFilePath, printSchemaTypes(federationInfo), "federation").write();
1813
+ return next();
1814
+ }
1815
+ });
1816
+ }
1817
+ function getModuleRootDir(modulesDir, options) {
1818
+ return `${modulesDir}/${options?.moduleName ?? DEFAULT_MODULE_NAME}`;
1819
+ }
1820
+ function buildDirectiveNames(spec, include = []) {
1821
+ if (include === "all") return new Set(spec.directives.map((d) => d.name));
1822
+ return new Set([...DEFAULT_DIRECTIVES, ...include]);
1823
+ }
1824
+ //#endregion
1825
+ export { federationPlugin };
1826
+
1827
+ //# sourceMappingURL=index.js.map