@wundergraph/composition 0.58.0 → 0.58.1

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 (124) hide show
  1. package/dist/{v1/normalization → directive-definition-data}/directive-definition-data.d.ts +2 -2
  2. package/dist/{v1/normalization → directive-definition-data}/directive-definition-data.js +308 -280
  3. package/dist/directive-definition-data/directive-definition-data.js.map +1 -0
  4. package/dist/directive-definition-data/types/params.d.ts +48 -0
  5. package/dist/directive-definition-data/types/params.js.map +1 -0
  6. package/dist/directive-definition-data/types/types.d.ts +39 -0
  7. package/dist/directive-definition-data/types/types.js.map +1 -0
  8. package/dist/directive-definition-data/utils.d.ts +5 -0
  9. package/dist/directive-definition-data/utils.js +75 -0
  10. package/dist/directive-definition-data/utils.js.map +1 -0
  11. package/dist/errors/errors.d.ts +35 -9
  12. package/dist/errors/errors.js +141 -21
  13. package/dist/errors/errors.js.map +1 -1
  14. package/dist/errors/{types.d.ts → types/params.d.ts} +34 -6
  15. package/dist/{federation → errors/types}/params.js.map +1 -1
  16. package/dist/errors/types/types.d.ts +5 -0
  17. package/dist/{federation → errors/types}/types.js.map +1 -1
  18. package/dist/federation/federation.d.ts +2 -2
  19. package/dist/federation/{params.d.ts → types/params.d.ts} +4 -4
  20. package/dist/{v1/federation → federation/types}/params.js.map +1 -1
  21. package/dist/federation/{types.d.ts → types/types.d.ts} +17 -20
  22. package/dist/{errors → federation/types}/types.js.map +1 -1
  23. package/dist/index.d.ts +16 -7
  24. package/dist/index.js +16 -7
  25. package/dist/index.js.map +1 -1
  26. package/dist/normalization/normalization.d.ts +2 -3
  27. package/dist/normalization/normalization.js +0 -8
  28. package/dist/normalization/normalization.js.map +1 -1
  29. package/dist/normalization/types.d.ts +21 -18
  30. package/dist/schema-building/ast.d.ts +2 -10
  31. package/dist/schema-building/ast.js +35 -32
  32. package/dist/schema-building/ast.js.map +1 -1
  33. package/dist/schema-building/types/params.d.ts +54 -0
  34. package/dist/schema-building/types/params.js.map +1 -0
  35. package/dist/schema-building/types/results.d.ts +39 -0
  36. package/dist/schema-building/types/results.js +3 -0
  37. package/dist/schema-building/types/results.js.map +1 -0
  38. package/dist/schema-building/{types.d.ts → types/types.d.ts} +21 -41
  39. package/dist/schema-building/types/types.js.map +1 -0
  40. package/dist/schema-building/utils.d.ts +21 -13
  41. package/dist/schema-building/utils.js +257 -82
  42. package/dist/schema-building/utils.js.map +1 -1
  43. package/dist/subgraph/types/params.d.ts +6 -0
  44. package/dist/subgraph/types/params.js +3 -0
  45. package/dist/{schema-building → subgraph/types}/params.js.map +1 -1
  46. package/dist/subgraph/types.d.ts +6 -6
  47. package/dist/subgraph/utils.d.ts +3 -0
  48. package/dist/subgraph/utils.js +23 -0
  49. package/dist/subgraph/utils.js.map +1 -0
  50. package/dist/tsconfig.tsbuildinfo +1 -1
  51. package/dist/types/results.d.ts +14 -0
  52. package/dist/types/results.js +3 -0
  53. package/dist/types/results.js.map +1 -0
  54. package/dist/types/types.d.ts +2 -0
  55. package/dist/utils/composition-version.js +1 -1
  56. package/dist/utils/params.d.ts +4 -0
  57. package/dist/utils/string-constants.d.ts +2 -1
  58. package/dist/utils/string-constants.js +5 -4
  59. package/dist/utils/string-constants.js.map +1 -1
  60. package/dist/utils/utils.d.ts +2 -1
  61. package/dist/utils/utils.js +14 -0
  62. package/dist/utils/utils.js.map +1 -1
  63. package/dist/v1/constants/directive-definitions.js +3 -3
  64. package/dist/v1/constants/directive-definitions.js.map +1 -1
  65. package/dist/v1/constants/strings.d.ts +3 -1
  66. package/dist/v1/constants/strings.js +12 -2
  67. package/dist/v1/constants/strings.js.map +1 -1
  68. package/dist/v1/federation/federation-factory.d.ts +15 -16
  69. package/dist/v1/federation/federation-factory.js +344 -213
  70. package/dist/v1/federation/federation-factory.js.map +1 -1
  71. package/dist/v1/federation/{params.d.ts → types/params.d.ts} +16 -9
  72. package/dist/v1/federation/types/params.js +3 -0
  73. package/dist/v1/federation/types/params.js.map +1 -0
  74. package/dist/v1/federation/utils.d.ts +2 -2
  75. package/dist/v1/normalization/batch-normalization/batch-normalizer.d.ts +37 -0
  76. package/dist/v1/normalization/batch-normalization/batch-normalizer.js +245 -0
  77. package/dist/v1/normalization/batch-normalization/batch-normalizer.js.map +1 -0
  78. package/dist/v1/normalization/batch-normalization/types/params.d.ts +6 -0
  79. package/dist/v1/normalization/batch-normalization/types/params.js +3 -0
  80. package/dist/v1/normalization/batch-normalization/types/params.js.map +1 -0
  81. package/dist/v1/normalization/normalization-factory.d.ts +20 -17
  82. package/dist/v1/normalization/normalization-factory.js +194 -424
  83. package/dist/v1/normalization/normalization-factory.js.map +1 -1
  84. package/dist/v1/normalization/{params.d.ts → types/params.d.ts} +6 -12
  85. package/dist/v1/normalization/types/params.js +3 -0
  86. package/dist/v1/normalization/types/params.js.map +1 -0
  87. package/dist/v1/normalization/types/results.d.ts +26 -0
  88. package/dist/v1/normalization/types/results.js +3 -0
  89. package/dist/v1/normalization/types/results.js.map +1 -0
  90. package/dist/v1/normalization/{types.d.ts → types/types.d.ts} +37 -19
  91. package/dist/v1/normalization/types/types.js +3 -0
  92. package/dist/v1/normalization/types/types.js.map +1 -0
  93. package/dist/v1/normalization/utils.d.ts +9 -2
  94. package/dist/v1/normalization/utils.js +308 -2
  95. package/dist/v1/normalization/utils.js.map +1 -1
  96. package/dist/v1/normalization/walkers.js +2 -1
  97. package/dist/v1/normalization/walkers.js.map +1 -1
  98. package/dist/v1/schema-building/type-merging.d.ts +1 -1
  99. package/dist/v1/utils/utils.d.ts +2 -3
  100. package/dist/v1/utils/utils.js +0 -17
  101. package/dist/v1/utils/utils.js.map +1 -1
  102. package/dist/v1/warnings/params.d.ts +6 -1
  103. package/dist/v1/warnings/warnings.d.ts +4 -1
  104. package/dist/v1/warnings/warnings.js +23 -0
  105. package/dist/v1/warnings/warnings.js.map +1 -1
  106. package/dist/validation/types/params.d.ts +22 -0
  107. package/dist/validation/types/params.js +3 -0
  108. package/dist/{v1/normalization → validation/types}/params.js.map +1 -1
  109. package/dist/validation/validation.d.ts +5 -0
  110. package/dist/validation/validation.js +213 -0
  111. package/dist/validation/validation.js.map +1 -0
  112. package/package.json +4 -3
  113. package/dist/schema-building/params.d.ts +0 -8
  114. package/dist/schema-building/types.js.map +0 -1
  115. package/dist/v1/normalization/directive-definition-data.js.map +0 -1
  116. package/dist/v1/normalization/types.js.map +0 -1
  117. /package/dist/{federation → directive-definition-data/types}/params.js +0 -0
  118. /package/dist/{errors → directive-definition-data/types}/types.js +0 -0
  119. /package/dist/{schema-building → errors/types}/params.js +0 -0
  120. /package/dist/{federation → errors/types}/types.js +0 -0
  121. /package/dist/{v1/federation → federation/types}/params.js +0 -0
  122. /package/dist/{v1/normalization → federation/types}/types.js +0 -0
  123. /package/dist/{v1/normalization → schema-building/types}/params.js +0 -0
  124. /package/dist/schema-building/{types.js → types/types.js} +0 -0
@@ -3,7 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.NormalizationFactory = void 0;
4
4
  exports.normalizeSubgraphFromString = normalizeSubgraphFromString;
5
5
  exports.normalizeSubgraph = normalizeSubgraph;
6
- exports.batchNormalize = batchNormalize;
7
6
  const graphql_1 = require("graphql");
8
7
  const utils_1 = require("../../ast/utils");
9
8
  const utils_2 = require("./utils");
@@ -13,10 +12,9 @@ const errors_1 = require("../../errors/errors");
13
12
  const strings_1 = require("../constants/strings");
14
13
  const buildASTSchema_1 = require("../../buildASTSchema/buildASTSchema");
15
14
  const merge_1 = require("@graphql-tools/merge");
16
- const subgraph_1 = require("../subgraph/subgraph");
17
15
  const warnings_1 = require("../warnings/warnings");
18
16
  const walkers_1 = require("./walkers");
19
- const types_1 = require("../../schema-building/types");
17
+ const types_1 = require("../../schema-building/types/types");
20
18
  const utils_4 = require("../../schema-building/utils");
21
19
  const ast_1 = require("../../schema-building/ast");
22
20
  const graph_1 = require("../../resolvability-graph/graph");
@@ -26,6 +24,8 @@ const integer_constants_1 = require("../../utils/integer-constants");
26
24
  const utils_5 = require("../../utils/utils");
27
25
  const utils_6 = require("../../router-configuration/utils");
28
26
  const non_directive_definitions_1 = require("../constants/non-directive-definitions");
27
+ const validation_1 = require("../../validation/validation");
28
+ const utils_7 = require("../../directive-definition-data/utils");
29
29
  function normalizeSubgraphFromString({ noLocation, options, sdlString, }) {
30
30
  const { error, documentNode } = (0, utils_1.safeParse)(sdlString, noLocation);
31
31
  if (error || !documentNode) {
@@ -64,7 +64,9 @@ class NormalizationFactory {
64
64
  entityDataByTypeName = new Map();
65
65
  entityInterfaceDataByTypeName = new Map();
66
66
  eventsConfigurations = new Map();
67
+ federatedDirectiveDataByName = new Map();
67
68
  fieldSetDataByTypeName = new Map();
69
+ importDataByDirectiveName = new Map();
68
70
  interfaceImplementationTypeNamesByInterfaceTypeName = new Map();
69
71
  internalGraph;
70
72
  invalidConfigureDescriptionNodeDatas = [];
@@ -85,12 +87,12 @@ class NormalizationFactory {
85
87
  operationTypeNodeByTypeName = new Map();
86
88
  originalParentTypeName = '';
87
89
  originalTypeNameByRenamedTypeName = new Map();
88
- overridesByTargetSubgraphName = new Map();
90
+ overriddenFieldNamesByTypeNameByTargetSubgraphName = new Map();
89
91
  parentDefinitionDataByTypeName = new Map();
90
- schemaData;
91
92
  referencedDirectiveNames = new Set();
92
93
  referencedTypeNames = new Set();
93
94
  renamedParentTypeName = '';
95
+ schemaData;
94
96
  subgraphName;
95
97
  unvalidatedExternalFieldCoords = new Set();
96
98
  usesEdfsNatsStreamConfiguration = false;
@@ -107,27 +109,6 @@ class NormalizationFactory {
107
109
  operationTypes: new Map(),
108
110
  };
109
111
  }
110
- sanitizeDefaultValue({ data, namedTypeData, node }) {
111
- if (!data.defaultValue) {
112
- return;
113
- }
114
- if (!(0, utils_4.isEnumData)(namedTypeData)) {
115
- return;
116
- }
117
- data.defaultValue = (0, graphql_1.visit)(data.defaultValue, {
118
- StringValue: {
119
- enter(node) {
120
- return {
121
- kind: graphql_1.Kind.ENUM,
122
- value: node.value,
123
- };
124
- },
125
- },
126
- });
127
- if (node) {
128
- node.defaultValue = data.defaultValue;
129
- }
130
- }
131
112
  validateArguments(fieldData, parentKind) {
132
113
  for (const argumentData of fieldData.argumentDataByName.values()) {
133
114
  const namedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(argumentData.type);
@@ -142,7 +123,7 @@ class NormalizationFactory {
142
123
  }
143
124
  if ((0, utils_4.isInputNodeKind)(namedTypeData.kind)) {
144
125
  argumentData.namedTypeKind = namedTypeData.kind;
145
- this.sanitizeDefaultValue({ data: argumentData, namedTypeData, node: argumentData.node });
126
+ (0, utils_4.sanitizeDefaultValue)({ data: argumentData, namedTypeData, node: argumentData.node });
146
127
  continue;
147
128
  }
148
129
  this.errors.push((0, errors_1.invalidNamedTypeError)({
@@ -155,89 +136,6 @@ class NormalizationFactory {
155
136
  isTypeNameRootType(typeName) {
156
137
  return string_constants_1.ROOT_TYPE_NAMES.has(typeName) || this.operationTypeNodeByTypeName.has(typeName);
157
138
  }
158
- isArgumentValueValid(typeNode, argumentValue) {
159
- if (argumentValue.kind === graphql_1.Kind.NULL) {
160
- return typeNode.kind !== graphql_1.Kind.NON_NULL_TYPE;
161
- }
162
- switch (typeNode.kind) {
163
- case graphql_1.Kind.LIST_TYPE: {
164
- if (argumentValue.kind !== graphql_1.Kind.LIST) {
165
- // This handles List coercion
166
- return this.isArgumentValueValid((0, ast_1.getNamedTypeNode)(typeNode.type), argumentValue);
167
- }
168
- for (const value of argumentValue.values) {
169
- if (!this.isArgumentValueValid(typeNode.type, value)) {
170
- return false;
171
- }
172
- }
173
- return true;
174
- }
175
- case graphql_1.Kind.NAMED_TYPE: {
176
- switch (typeNode.name.value) {
177
- case string_constants_1.BOOLEAN_SCALAR: {
178
- return argumentValue.kind === graphql_1.Kind.BOOLEAN;
179
- }
180
- case string_constants_1.FLOAT_SCALAR: {
181
- return argumentValue.kind === graphql_1.Kind.FLOAT || argumentValue.kind === graphql_1.Kind.INT;
182
- }
183
- case string_constants_1.ID_SCALAR: {
184
- return argumentValue.kind === graphql_1.Kind.STRING || argumentValue.kind === graphql_1.Kind.INT;
185
- }
186
- case string_constants_1.INT_SCALAR: {
187
- return argumentValue.kind === graphql_1.Kind.INT;
188
- }
189
- case string_constants_1.FIELD_SET_SCALAR:
190
- // intentional fallthrough
191
- case string_constants_1.SCOPE_SCALAR:
192
- // intentional fallthrough
193
- case string_constants_1.STRING_SCALAR: {
194
- return argumentValue.kind === graphql_1.Kind.STRING;
195
- }
196
- case string_constants_1.LINK_IMPORT: {
197
- return true;
198
- }
199
- case string_constants_1.LINK_PURPOSE: {
200
- if (argumentValue.kind !== graphql_1.Kind.ENUM) {
201
- return false;
202
- }
203
- return argumentValue.value === string_constants_1.SECURITY || argumentValue.value === string_constants_1.EXECUTION;
204
- }
205
- case string_constants_1.SUBSCRIPTION_FIELD_CONDITION:
206
- // intentional fallthrough
207
- case string_constants_1.SUBSCRIPTION_FILTER_CONDITION:
208
- return argumentValue.kind === graphql_1.Kind.OBJECT;
209
- default: {
210
- const parentData = this.parentDefinitionDataByTypeName.get(typeNode.name.value);
211
- if (!parentData) {
212
- return false;
213
- }
214
- if (parentData.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
215
- // For now, allow custom scalars to be any value kind.
216
- return true;
217
- }
218
- if (parentData.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
219
- if (argumentValue.kind !== graphql_1.Kind.ENUM && argumentValue.kind !== graphql_1.Kind.STRING) {
220
- return false;
221
- }
222
- const enumValue = parentData.enumValueDataByName.get(argumentValue.value);
223
- if (!enumValue) {
224
- return false;
225
- }
226
- return !enumValue.directivesByName.has(string_constants_1.INACCESSIBLE);
227
- }
228
- if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
229
- return false;
230
- }
231
- // TODO deep comparison
232
- return argumentValue.kind === graphql_1.Kind.OBJECT;
233
- }
234
- }
235
- }
236
- default: {
237
- return this.isArgumentValueValid(typeNode.type, argumentValue);
238
- }
239
- }
240
- }
241
139
  handleFieldInheritableDirectives({ directivesByName, fieldName, inheritedDirectiveNames, parentData, }) {
242
140
  if (this.doesParentRequireFetchReasons && !directivesByName.has(string_constants_1.REQUIRE_FETCH_REASONS)) {
243
141
  directivesByName.set(string_constants_1.REQUIRE_FETCH_REASONS, [(0, utils_5.generateSimpleDirective)(string_constants_1.REQUIRE_FETCH_REASONS)]);
@@ -269,8 +167,8 @@ class NormalizationFactory {
269
167
  const isObjectKind = (0, utils_3.isObjectNodeKind)(node.kind);
270
168
  for (const directiveNode of node.directives) {
271
169
  const directiveName = directiveNode.name.value;
272
- // Don't create pointless repetitions of @shareable
273
170
  if (directiveName === string_constants_1.SHAREABLE) {
171
+ // @shareable need only be propagated once
274
172
  (0, utils_5.getValueOrDefault)(directivesByName, directiveName, () => [directiveNode]);
275
173
  }
276
174
  else {
@@ -339,13 +237,17 @@ class NormalizationFactory {
339
237
  continue;
340
238
  }
341
239
  definedArgumentNames.add(argumentName);
342
- const argumentData = definitionData.argumentTypeNodeByName.get(argumentName);
240
+ const argumentData = definitionData.argumentDataByName.get(argumentName);
343
241
  if (!argumentData) {
344
242
  unexpectedArgumentNames.add(argumentName);
345
243
  continue;
346
244
  }
347
- if (!this.isArgumentValueValid(argumentData.typeNode, argumentNode.value)) {
348
- errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(argumentNode.value), `@${directiveName}`, argumentName, (0, merge_1.printTypeNode)(argumentData.typeNode)));
245
+ if (!(0, validation_1.isArgumentValueValid)({
246
+ argumentValue: argumentNode.value,
247
+ parentDefinitionDataByTypeName: this.parentDefinitionDataByTypeName,
248
+ typeNode: argumentData.type,
249
+ })) {
250
+ errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(argumentNode.value), `@${directiveName}`, argumentName, (0, merge_1.printTypeNode)(argumentData.type)));
349
251
  continue;
350
252
  }
351
253
  /* Individual directives are handled in the loop because they validate a single argument, and duplicate
@@ -415,6 +317,49 @@ class NormalizationFactory {
415
317
  }
416
318
  return errorMessages;
417
319
  }
320
+ handleComposeDirective(node) {
321
+ const argNode = node.arguments[0];
322
+ if (!argNode) {
323
+ return;
324
+ }
325
+ const rawValue = argNode.value.value;
326
+ if (!rawValue.startsWith(string_constants_1.LITERAL_AT)) {
327
+ this.errors.push((0, errors_1.noLeadingAtComposeDirectiveNameError)(rawValue));
328
+ return;
329
+ }
330
+ const directiveName = rawValue.substring(1);
331
+ if (constants_1.DIRECTIVE_DEFINITION_BY_NAME.has(directiveName)) {
332
+ if (directiveName === string_constants_1.ONE_OF) {
333
+ this.warnings.push((0, warnings_1.composedOneOfDirectiveWarning)(this.subgraphName));
334
+ }
335
+ else {
336
+ this.errors.push((0, errors_1.invalidComposeDirectiveNameError)(rawValue));
337
+ return;
338
+ }
339
+ }
340
+ const definitionData = this.directiveDefinitionDataByName.get(directiveName);
341
+ if (!definitionData) {
342
+ this.errors.push((0, errors_1.unknownComposeDirectiveNameError)(rawValue));
343
+ return;
344
+ }
345
+ const importData = this.importDataByDirectiveName.get(rawValue);
346
+ if (!importData) {
347
+ this.errors.push((0, errors_1.unimportedComposeDirectiveNameError)(rawValue));
348
+ return;
349
+ }
350
+ definitionData.majorVersion = importData.majorVersion;
351
+ definitionData.minorVersion = importData.minorVersion;
352
+ definitionData.isComposed = true;
353
+ this.federatedDirectiveDataByName.set(directiveName, definitionData);
354
+ }
355
+ handleExecutableDirectives() {
356
+ for (const [directiveName, definitionData] of this.directiveDefinitionDataByName) {
357
+ if (definitionData.isComposed || definitionData.executableLocations.size < 1) {
358
+ continue;
359
+ }
360
+ this.federatedDirectiveDataByName.set(directiveName, definitionData);
361
+ }
362
+ }
418
363
  validateDirectives(data, directiveCoords) {
419
364
  const undefinedDirectiveNames = new Set();
420
365
  for (const [directiveName, directiveNodes] of data.directivesByName) {
@@ -426,6 +371,9 @@ class NormalizationFactory {
426
371
  }
427
372
  continue;
428
373
  }
374
+ if (definitionData.isComposed) {
375
+ definitionData.isReferenced = true;
376
+ }
429
377
  const definitionErrorMessages = [];
430
378
  const directiveLocation = (0, utils_1.nodeKindToDirectiveLocation)(data.kind);
431
379
  if (!definitionData.locations.has(directiveLocation)) {
@@ -443,21 +391,22 @@ class NormalizationFactory {
443
391
  if (!argumentNode.defaultValue) {
444
392
  continue;
445
393
  }
446
- const argumentData = definitionData.argumentTypeNodeByName.get(argumentNode.name.value);
394
+ const argumentData = definitionData.argumentDataByName.get(argumentNode.name.value);
447
395
  if (!argumentData) {
448
396
  continue;
449
397
  }
450
- const namedTypeData = this.parentDefinitionDataByTypeName.get((0, ast_1.getTypeNodeNamedTypeName)(argumentData.typeNode));
398
+ const namedTypeData = this.parentDefinitionDataByTypeName.get((0, ast_1.getTypeNodeNamedTypeName)(argumentData.type));
451
399
  // Undefined types are handled elsewhere
452
400
  if (!namedTypeData) {
453
401
  continue;
454
402
  }
455
- this.sanitizeDefaultValue({ data: argumentData, namedTypeData, node: argumentNode });
403
+ (0, utils_4.sanitizeDefaultValue)({ data: argumentData, namedTypeData, node: argumentNode });
456
404
  }
457
405
  for (let i = 0; i < directiveNodes.length; i++) {
406
+ const directiveNode = directiveNodes[i];
458
407
  const errorMessages = this.validateDirective({
459
408
  data,
460
- directiveNode: directiveNodes[i],
409
+ directiveNode,
461
410
  definitionData,
462
411
  directiveCoords,
463
412
  errorMessages: i < 1 ? definitionErrorMessages : [],
@@ -555,14 +504,14 @@ class NormalizationFactory {
555
504
  for (const argument of directiveNode.arguments) {
556
505
  switch (argument.name.value) {
557
506
  case string_constants_1.PROPAGATE: {
558
- if (argument.value.kind != graphql_1.Kind.BOOLEAN) {
507
+ if (argument.value.kind !== graphql_1.Kind.BOOLEAN) {
559
508
  return;
560
509
  }
561
510
  configureDescriptionData.propagate = argument.value.value;
562
511
  break;
563
512
  }
564
513
  case string_constants_1.DESCRIPTION_OVERRIDE: {
565
- if (argument.value.kind != graphql_1.Kind.STRING) {
514
+ if (argument.value.kind !== graphql_1.Kind.STRING) {
566
515
  return;
567
516
  }
568
517
  configureDescriptionData.description = argument.value.value;
@@ -649,55 +598,12 @@ class NormalizationFactory {
649
598
  }
650
599
  return argumentDataByName;
651
600
  }
652
- addPersistedDirectiveDefinitionDataByNode(persistedDirectiveDefinitionDataByDirectiveName, node, executableLocations) {
653
- const name = node.name.value;
654
- const directiveName = `@${name}`;
601
+ extractDirectiveArgumentData({ argumentNodes, directiveName, errorMessages, }) {
655
602
  const argumentDataByName = new Map();
656
- for (const argumentNode of node.arguments || []) {
657
- this.addInputValueDataByNode({
658
- inputValueDataByName: argumentDataByName,
659
- isArgument: true,
660
- node: argumentNode,
661
- originalParentTypeName: directiveName,
662
- });
663
- }
664
- persistedDirectiveDefinitionDataByDirectiveName.set(name, {
665
- argumentDataByName: argumentDataByName,
666
- executableLocations,
667
- name,
668
- repeatable: node.repeatable,
669
- subgraphNames: new Set([this.subgraphName]),
670
- description: (0, utils_1.formatDescription)(node.description),
671
- });
672
- }
673
- extractDirectiveLocations(node, errorMessages) {
674
- const locations = new Set();
675
- const handledLocations = new Set();
676
- for (const locationNode of node.locations) {
677
- const locationName = locationNode.value;
678
- if (handledLocations.has(locationName)) {
679
- continue;
680
- }
681
- if (!string_constants_1.EXECUTABLE_DIRECTIVE_LOCATIONS.has(locationName) && !strings_1.TYPE_SYSTEM_DIRECTIVE_LOCATIONS.has(locationName)) {
682
- errorMessages.push((0, errors_1.invalidDirectiveDefinitionLocationErrorMessage)(locationName));
683
- handledLocations.add(locationName);
684
- continue;
685
- }
686
- if (locations.has(locationName)) {
687
- errorMessages.push((0, errors_1.duplicateDirectiveDefinitionLocationErrorMessage)(locationName));
688
- handledLocations.add(locationName);
689
- continue;
690
- }
691
- locations.add(locationName);
692
- }
693
- return locations;
694
- }
695
- extractArgumentData(argumentNodes, errorMessages) {
696
- const argumentTypeNodeByName = new Map();
697
603
  const optionalArgumentNames = new Set();
698
604
  const requiredArgumentNames = new Set();
699
605
  const output = {
700
- argumentTypeNodeByName,
606
+ argumentDataByName,
701
607
  optionalArgumentNames,
702
608
  requiredArgumentNames,
703
609
  };
@@ -705,23 +611,13 @@ class NormalizationFactory {
705
611
  return output;
706
612
  }
707
613
  const duplicateArgumentNames = new Set();
708
- for (const argumentNode of argumentNodes) {
709
- const name = argumentNode.name.value;
710
- if (argumentTypeNodeByName.has(name)) {
614
+ for (const node of argumentNodes) {
615
+ const name = node.name.value;
616
+ if (argumentDataByName.has(name)) {
711
617
  duplicateArgumentNames.add(name);
712
618
  continue;
713
619
  }
714
- if (argumentNode.defaultValue) {
715
- optionalArgumentNames.add(name);
716
- }
717
- if ((0, utils_4.isTypeRequired)(argumentNode.type) && !argumentNode.defaultValue) {
718
- requiredArgumentNames.add(name);
719
- }
720
- argumentTypeNodeByName.set(name, {
721
- name,
722
- typeNode: argumentNode.type,
723
- defaultValue: argumentNode.defaultValue,
724
- });
620
+ argumentDataByName.set(name, this.addDirectiveArgumentDataByNode({ directiveName, node, optionalArgumentNames, requiredArgumentNames }));
725
621
  }
726
622
  if (duplicateArgumentNames.size > 0) {
727
623
  errorMessages.push((0, errors_1.duplicateDirectiveDefinitionArgumentErrorMessage)([...duplicateArgumentNames]));
@@ -759,6 +655,35 @@ class NormalizationFactory {
759
655
  }
760
656
  }
761
657
  }
658
+ addDirectiveArgumentDataByNode({ directiveName, node, optionalArgumentNames, requiredArgumentNames, }) {
659
+ const name = node.name.value;
660
+ const parentName = `@${directiveName}`;
661
+ if (node.defaultValue && !(0, utils_4.areDefaultValuesCompatible)(node.type, node.defaultValue)) {
662
+ this.errors.push((0, errors_1.incompatibleInputValueDefaultValueTypeError)(`argument "${name}"`, parentName, (0, merge_1.printTypeNode)(node.type), (0, graphql_1.print)(node.defaultValue)));
663
+ }
664
+ const isRequired = (0, utils_4.isTypeRequired)(node.type);
665
+ if (node.defaultValue) {
666
+ optionalArgumentNames.add(name);
667
+ }
668
+ else if (isRequired) {
669
+ requiredArgumentNames.add(name);
670
+ }
671
+ const namedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(node.type);
672
+ const argumentData = (0, utils_7.newDirectiveArgumentData)({
673
+ name,
674
+ directive: `@${directiveName}`,
675
+ directivesByName: this.extractDirectives(node, new Map()),
676
+ defaultValue: node.defaultValue,
677
+ description: (0, utils_1.formatDescription)(node.description),
678
+ namedTypeKind: constants_1.BASE_SCALARS.has(namedTypeName) ? graphql_1.Kind.SCALAR_TYPE_DEFINITION : graphql_1.Kind.NULL,
679
+ node: (0, ast_1.getMutableInputValueNode)(node, parentName, this.errors),
680
+ requiredSubgraphNames: new Set(isRequired ? [this.subgraphName] : []),
681
+ subgraphNames: new Set([this.subgraphName]),
682
+ typeNode: (0, ast_1.getMutableTypeNode)(node.type, parentName, this.errors),
683
+ });
684
+ this.extractConfigureDescriptionsData(argumentData);
685
+ return argumentData;
686
+ }
762
687
  // returns true if the directive is custom; otherwise, false
763
688
  addDirectiveDefinitionDataByNode(node) {
764
689
  const name = node.name.value;
@@ -782,30 +707,42 @@ class NormalizationFactory {
782
707
  return false;
783
708
  }
784
709
  this.directiveDefinitionByName.set(name, node);
710
+ // @TODO
785
711
  const errorMessages = [];
786
- const { argumentTypeNodeByName, optionalArgumentNames, requiredArgumentNames } = this.extractArgumentData(node.arguments, errorMessages);
787
- this.directiveDefinitionDataByName.set(name, {
788
- argumentTypeNodeByName: argumentTypeNodeByName,
712
+ const { argumentDataByName, optionalArgumentNames, requiredArgumentNames } = this.extractDirectiveArgumentData({
713
+ argumentNodes: node.arguments,
714
+ directiveName: name,
715
+ errorMessages,
716
+ });
717
+ const { errors, locations } = (0, ast_1.extractDirectiveLocations)(node);
718
+ // @TODO
719
+ if (errors.length > 0) {
720
+ this.errors.push(...errors);
721
+ }
722
+ this.directiveDefinitionDataByName.set(name, (0, utils_7.newDirectiveDefinitionData)({
723
+ argumentDataByName: argumentDataByName,
724
+ description: node.description,
789
725
  isRepeatable: node.repeatable,
790
- locations: this.extractDirectiveLocations(node, errorMessages),
726
+ locations,
791
727
  name,
792
728
  node,
793
729
  optionalArgumentNames,
794
730
  requiredArgumentNames,
795
- });
731
+ subgraphNames: new Set([this.subgraphName]),
732
+ }));
796
733
  if (errorMessages.length > 0) {
797
734
  this.errors.push((0, errors_1.invalidDirectiveDefinitionError)(name, errorMessages));
798
735
  }
799
736
  return true;
800
737
  }
801
- addFieldDataByNode(fieldDataByFieldName, node, argumentDataByArgumentName, directivesByName, inheritedDirectiveNames = new Set()) {
738
+ addFieldDataByNode(fieldDataByName, node, argumentDataByName, directivesByName, inheritedDirectiveNames = new Set()) {
802
739
  const name = node.name.value;
803
740
  const parentTypeName = this.renamedParentTypeName || this.originalParentTypeName;
804
741
  const fieldCoords = `${this.originalParentTypeName}.${name}`;
805
742
  const { isExternal, isShareable } = (0, utils_4.isNodeExternalOrShareable)(node, !this.isSubgraphVersionTwo, directivesByName);
806
743
  const namedTypeName = (0, ast_1.getTypeNodeNamedTypeName)(node.type);
807
744
  const fieldData = {
808
- argumentDataByName: argumentDataByArgumentName,
745
+ argumentDataByName: argumentDataByName,
809
746
  configureDescriptionDataBySubgraphName: new Map(),
810
747
  externalFieldDataBySubgraphName: new Map([
811
748
  [this.subgraphName, (0, utils_4.newExternalFieldData)(isExternal)],
@@ -821,7 +758,7 @@ class NormalizationFactory {
821
758
  node: (0, ast_1.getMutableFieldNode)(node, fieldCoords, this.errors),
822
759
  nullLevelsBySubgraphName: new Map(),
823
760
  originalParentTypeName: this.originalParentTypeName,
824
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
761
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
825
762
  renamedParentTypeName: parentTypeName,
826
763
  subgraphNames: new Set([this.subgraphName]),
827
764
  type: (0, ast_1.getMutableTypeNode)(node.type, fieldCoords, this.errors),
@@ -832,7 +769,7 @@ class NormalizationFactory {
832
769
  this.referencedTypeNames.add(fieldData.namedTypeName);
833
770
  }
834
771
  this.extractConfigureDescriptionsData(fieldData);
835
- fieldDataByFieldName.set(name, fieldData);
772
+ fieldDataByName.set(name, fieldData);
836
773
  return fieldData;
837
774
  }
838
775
  addInputValueDataByNode({ fieldName, inputValueDataByName, isArgument, node, originalParentTypeName, renamedParentTypeName, }) {
@@ -863,7 +800,7 @@ class NormalizationFactory {
863
800
  node: (0, ast_1.getMutableInputValueNode)(node, originalParentTypeName, this.errors),
864
801
  originalCoords,
865
802
  originalParentTypeName: originalParentTypeName,
866
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
803
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
867
804
  renamedParentTypeName: federatedParentTypeName,
868
805
  requiredSubgraphNames: new Set((0, utils_4.isTypeRequired)(node.type) ? [this.subgraphName] : []),
869
806
  subgraphNames: new Set([this.subgraphName]),
@@ -904,7 +841,7 @@ class NormalizationFactory {
904
841
  kind: graphql_1.Kind.INTERFACE_TYPE_DEFINITION,
905
842
  name: typeName,
906
843
  node: (0, ast_1.getMutableInterfaceNode)(node.name),
907
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
844
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
908
845
  requireFetchReasonsFieldNames: new Set(),
909
846
  subgraphNames: new Set([this.subgraphName]),
910
847
  description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
@@ -970,7 +907,7 @@ class NormalizationFactory {
970
907
  kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
971
908
  name: typeName,
972
909
  node: (0, ast_1.getMutableObjectNode)(node.name),
973
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
910
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
974
911
  requireFetchReasonsFieldNames: new Set(),
975
912
  renamedTypeName: this.getRenamedRootTypeName(typeName),
976
913
  subgraphNames: new Set([this.subgraphName]),
@@ -1007,7 +944,7 @@ class NormalizationFactory {
1007
944
  kind: graphql_1.Kind.ENUM_TYPE_DEFINITION,
1008
945
  name: typeName,
1009
946
  node: (0, ast_1.getMutableEnumNode)(node.name),
1010
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
947
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
1011
948
  subgraphNames: new Set([this.subgraphName]),
1012
949
  description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
1013
950
  };
@@ -1021,6 +958,7 @@ class NormalizationFactory {
1021
958
  const extensionType = this.getNodeExtensionType(isRealExtension, directivesByName);
1022
959
  if (parentData) {
1023
960
  if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
961
+ // TODO
1024
962
  this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_5.kindToNodeType)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
1025
963
  return {
1026
964
  success: false,
@@ -1045,7 +983,7 @@ class NormalizationFactory {
1045
983
  kind: graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION,
1046
984
  name: typeName,
1047
985
  node: (0, ast_1.getMutableInputObjectNode)(node.name),
1048
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
986
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
1049
987
  subgraphNames: new Set([this.subgraphName]),
1050
988
  description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
1051
989
  };
@@ -1080,7 +1018,7 @@ class NormalizationFactory {
1080
1018
  kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
1081
1019
  name: typeName,
1082
1020
  node: (0, ast_1.getMutableScalarNode)(node.name),
1083
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
1021
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
1084
1022
  subgraphNames: new Set([this.subgraphName]),
1085
1023
  description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
1086
1024
  };
@@ -1139,7 +1077,7 @@ class NormalizationFactory {
1139
1077
  memberByMemberTypeName: this.extractUnionMembers(node, new Map()),
1140
1078
  name: typeName,
1141
1079
  node: (0, ast_1.getMutableUnionNode)(node.name),
1142
- persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
1080
+ federatedDirectivesData: (0, utils_4.newFederatedDirectivesData)(),
1143
1081
  subgraphNames: new Set([this.subgraphName]),
1144
1082
  description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
1145
1083
  };
@@ -1685,7 +1623,7 @@ class NormalizationFactory {
1685
1623
  errorMessages.push((0, errors_1.equivalentSourceAndTargetOverrideErrorMessage)(targetSubgraphName, directiveCoords));
1686
1624
  return;
1687
1625
  }
1688
- const overrideDataForSubgraph = (0, utils_5.getValueOrDefault)(this.overridesByTargetSubgraphName, targetSubgraphName, () => new Map());
1626
+ const overrideDataForSubgraph = (0, utils_5.getValueOrDefault)(this.overriddenFieldNamesByTypeNameByTargetSubgraphName, targetSubgraphName, () => new Map());
1689
1627
  (0, utils_5.getValueOrDefault)(overrideDataForSubgraph, data.renamedParentTypeName, () => new Set()).add(data.name);
1690
1628
  }
1691
1629
  handleSemanticNonNullDirective({ data, directiveNode, errorMessages }) {
@@ -1825,7 +1763,7 @@ class NormalizationFactory {
1825
1763
  for (const arg of directiveNode.arguments ?? []) {
1826
1764
  suppliedArgNodeByName.set(arg.name.value, arg.value);
1827
1765
  }
1828
- for (const [argName, argData] of definitionData.argumentTypeNodeByName) {
1766
+ for (const [argName, argData] of definitionData.argumentDataByName) {
1829
1767
  const coords = `${directiveName}.${argName}`;
1830
1768
  const argWeight = this.costs.directiveArgumentWeights.get(coords);
1831
1769
  // Bail if the argName argument does not have cost attached to it.
@@ -2150,7 +2088,7 @@ class NormalizationFactory {
2150
2088
  }
2151
2089
  switch (fieldName) {
2152
2090
  case string_constants_1.CONSUMER_NAME:
2153
- if (field.value.kind != graphql_1.Kind.STRING || field.value.value.length < 1) {
2091
+ if (field.value.kind !== graphql_1.Kind.STRING || field.value.value.length < 1) {
2154
2092
  invalidRequiredFieldNames.add(fieldName);
2155
2093
  isValid = false;
2156
2094
  continue;
@@ -2158,7 +2096,7 @@ class NormalizationFactory {
2158
2096
  consumerName = field.value.value;
2159
2097
  break;
2160
2098
  case string_constants_1.STREAM_NAME:
2161
- if (field.value.kind != graphql_1.Kind.STRING || field.value.value.length < 1) {
2099
+ if (field.value.kind !== graphql_1.Kind.STRING || field.value.value.length < 1) {
2162
2100
  invalidRequiredFieldNames.add(fieldName);
2163
2101
  isValid = false;
2164
2102
  continue;
@@ -2166,7 +2104,7 @@ class NormalizationFactory {
2166
2104
  streamName = field.value.value;
2167
2105
  break;
2168
2106
  case string_constants_1.CONSUMER_INACTIVE_THRESHOLD:
2169
- if (field.value.kind != graphql_1.Kind.INT) {
2107
+ if (field.value.kind !== graphql_1.Kind.INT) {
2170
2108
  errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(field.value), 'edfs__NatsStreamConfiguration', `consumerInactiveThreshold`, string_constants_1.INT_SCALAR));
2171
2109
  isValid = false;
2172
2110
  continue;
@@ -2464,7 +2402,7 @@ class NormalizationFactory {
2464
2402
  if (data.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
2465
2403
  return false;
2466
2404
  }
2467
- if (data.fieldDataByName.size != 1) {
2405
+ if (data.fieldDataByName.size !== 1) {
2468
2406
  return false;
2469
2407
  }
2470
2408
  for (const [fieldName, fieldData] of data.fieldDataByName) {
@@ -2484,7 +2422,7 @@ class NormalizationFactory {
2484
2422
  if (!(0, utils_4.isInputObjectDefinitionData)(streamConfigurationInputData)) {
2485
2423
  return false;
2486
2424
  }
2487
- if (streamConfigurationInputData.inputValueDataByName.size != 3) {
2425
+ if (streamConfigurationInputData.inputValueDataByName.size !== 3) {
2488
2426
  return false;
2489
2427
  }
2490
2428
  for (const [inputValueName, inputValueData] of streamConfigurationInputData.inputValueDataByName) {
@@ -2720,7 +2658,7 @@ class NormalizationFactory {
2720
2658
  scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByName, scalarDefinitionData.name);
2721
2659
  return scalarDefinitionData.node;
2722
2660
  }
2723
- getSchemaNodeByData(schemaData) {
2661
+ schemaNodeFromData(schemaData) {
2724
2662
  const operationTypes = [];
2725
2663
  for (const [operation, { type: { name: { value }, }, },] of schemaData.operationTypes) {
2726
2664
  const data = this.parentDefinitionDataByTypeName.get(value);
@@ -2733,21 +2671,44 @@ class NormalizationFactory {
2733
2671
  type: (0, utils_1.stringToNamedTypeNode)(value),
2734
2672
  });
2735
2673
  }
2674
+ const linkResult = (0, utils_2.extractLinkArgs)(schemaData.directivesByName);
2675
+ if (!linkResult.success) {
2676
+ return linkResult;
2677
+ }
2678
+ this.importDataByDirectiveName = linkResult.importDataByDirectiveName;
2679
+ const composeDirectives = schemaData.directivesByName.get(string_constants_1.COMPOSE_DIRECTIVE);
2680
+ for (const composeDirective of composeDirectives ?? []) {
2681
+ this.handleComposeDirective(composeDirective);
2682
+ }
2683
+ // If the directive is not part of @composeDirective, it is effectively ignored by federation.
2684
+ for (const directiveName of this.importDataByDirectiveName.keys()) {
2685
+ if (!this.federatedDirectiveDataByName.has(directiveName.substring(1))) {
2686
+ this.importDataByDirectiveName.delete(directiveName);
2687
+ }
2688
+ }
2736
2689
  if (operationTypes.length > 0) {
2737
- const node = {
2738
- ...(schemaData.description ? { description: schemaData.description } : {}),
2739
- directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
2740
- kind: graphql_1.Kind.SCHEMA_DEFINITION,
2741
- operationTypes: operationTypes,
2690
+ return {
2691
+ node: {
2692
+ ...(schemaData.description ? { description: schemaData.description } : {}),
2693
+ directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
2694
+ kind: graphql_1.Kind.SCHEMA_DEFINITION,
2695
+ operationTypes: operationTypes,
2696
+ },
2697
+ success: true,
2742
2698
  };
2743
- return node;
2744
2699
  }
2745
2700
  if (schemaData.directivesByName.size < 1) {
2746
- return;
2701
+ return {
2702
+ node: undefined,
2703
+ success: true,
2704
+ };
2747
2705
  }
2748
2706
  return {
2749
- directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
2750
- kind: graphql_1.Kind.SCHEMA_EXTENSION,
2707
+ node: {
2708
+ directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByName, schemaData.name),
2709
+ kind: graphql_1.Kind.SCHEMA_EXTENSION,
2710
+ },
2711
+ success: true,
2751
2712
  };
2752
2713
  }
2753
2714
  getUnionNodeByData(unionDefinitionData) {
@@ -2976,14 +2937,22 @@ class NormalizationFactory {
2976
2937
  const definitions = [];
2977
2938
  this.#addDirectiveDefinitionsToDocument(definitions);
2978
2939
  this.validateDirectives(this.schemaData, string_constants_1.SCHEMA);
2979
- const schemaNode = this.getSchemaNodeByData(this.schemaData);
2940
+ const schemaNodeResult = this.schemaNodeFromData(this.schemaData);
2941
+ if (!schemaNodeResult.success) {
2942
+ this.errors.push(...schemaNodeResult.errors);
2943
+ return {
2944
+ errors: this.errors,
2945
+ success: false,
2946
+ warnings: this.warnings,
2947
+ };
2948
+ }
2980
2949
  /* Schema extension orphans are not supported on old routers.
2981
2950
  * Consequently, it is a breaking change that requires a new composition version, and that composition version
2982
2951
  * would only be compatible with newer routers that support schema extension orphans.
2983
2952
  * For now, only a valid schema definition node is pushed.
2984
2953
  */
2985
- if (schemaNode?.kind === graphql_1.Kind.SCHEMA_DEFINITION) {
2986
- definitions.push(schemaNode);
2954
+ if (schemaNodeResult.node?.kind === graphql_1.Kind.SCHEMA_DEFINITION) {
2955
+ definitions.push(schemaNodeResult.node);
2987
2956
  }
2988
2957
  for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
2989
2958
  this.validateDirectives(parentData, parentTypeName);
@@ -3031,7 +3000,7 @@ class NormalizationFactory {
3031
3000
  // Undefined types are handled elsewhere
3032
3001
  continue;
3033
3002
  }
3034
- this.sanitizeDefaultValue({ data: valueData, namedTypeData, node: valueData.node });
3003
+ (0, utils_4.sanitizeDefaultValue)({ data: valueData, namedTypeData, node: valueData.node });
3035
3004
  if (!(0, utils_4.isInputNodeKind)(namedTypeData.kind)) {
3036
3005
  this.errors.push((0, errors_1.invalidNamedTypeError)({
3037
3006
  data: valueData,
@@ -3209,15 +3178,7 @@ class NormalizationFactory {
3209
3178
  this.warnings.push((0, warnings_1.unimplementedInterfaceOutputTypeWarning)(this.subgraphName, referencedTypeName));
3210
3179
  }
3211
3180
  }
3212
- const persistedDirectiveDefinitionDataByDirectiveName = new Map();
3213
- for (const directiveDefinitionNode of this.directiveDefinitionByName.values()) {
3214
- // TODO @composeDirective directives would also be handled here
3215
- const executableLocations = (0, utils_1.extractExecutableDirectiveLocations)(directiveDefinitionNode.locations, new Set());
3216
- if (executableLocations.size < 1) {
3217
- continue;
3218
- }
3219
- this.addPersistedDirectiveDefinitionDataByNode(persistedDirectiveDefinitionDataByDirectiveName, directiveDefinitionNode, executableLocations);
3220
- }
3181
+ this.handleExecutableDirectives();
3221
3182
  if (this.isSubgraphEventDrivenGraph) {
3222
3183
  this.validateEventDrivenSubgraph();
3223
3184
  }
@@ -3238,16 +3199,19 @@ class NormalizationFactory {
3238
3199
  };
3239
3200
  return {
3240
3201
  authorizationDataByParentTypeName: this.authorizationDataByParentTypeName,
3241
- // configurationDataMap is map of ConfigurationData per type name.
3242
- // It is an Intermediate configuration object that will be converted to an engine configuration in the router
3243
3202
  concreteTypeNamesByAbstractTypeName: this.concreteTypeNamesByAbstractTypeName,
3244
3203
  conditionalFieldDataByCoordinates: this.conditionalFieldDataByCoords,
3204
+ /* `configurationDataByTypeName` is an intermediate object that is converted
3205
+ * to an engine configuration in the router
3206
+ */
3245
3207
  configurationDataByTypeName: this.configurationDataByTypeName,
3246
3208
  costs: this.costs,
3247
3209
  directiveDefinitionByName: this.directiveDefinitionByName,
3248
3210
  entityDataByTypeName: this.entityDataByTypeName,
3249
3211
  entityInterfaces: this.entityInterfaceDataByTypeName,
3212
+ federatedDirectiveDataByName: this.federatedDirectiveDataByName,
3250
3213
  fieldCoordsByNamedTypeName: this.fieldCoordsByNamedTypeName,
3214
+ importDataByDirectiveName: this.importDataByDirectiveName,
3251
3215
  interfaceImplementationTypeNamesByInterfaceTypeName: this.interfaceImplementationTypeNamesByInterfaceTypeName,
3252
3216
  isEventDrivenGraph: this.isSubgraphEventDrivenGraph,
3253
3217
  isVersionTwo: this.isSubgraphVersionTwo,
@@ -3255,210 +3219,16 @@ class NormalizationFactory {
3255
3219
  keyFieldSetsByEntityTypeNameByKeyFieldCoords: this.keyFieldSetsByEntityTypeNameByFieldCoords,
3256
3220
  operationTypes: this.operationTypeNodeByTypeName,
3257
3221
  originalTypeNameByRenamedTypeName: this.originalTypeNameByRenamedTypeName,
3258
- overridesByTargetSubgraphName: this.overridesByTargetSubgraphName,
3222
+ overriddenFieldNamesByParentTypeNameByTargetSubgraphName: this.overriddenFieldNamesByTypeNameByTargetSubgraphName,
3259
3223
  parentDefinitionDataByTypeName: this.parentDefinitionDataByTypeName,
3260
- persistedDirectiveDefinitionDataByDirectiveName,
3261
- schemaNode,
3224
+ schema: (0, buildASTSchema_1.buildASTSchema)(newAST, { addInvalidExtensionOrphans: true, assumeValid: true, assumeValidSDL: true }),
3225
+ schemaNode: schemaNodeResult.node,
3262
3226
  subgraphAST: newAST,
3263
3227
  subgraphString: (0, graphql_1.print)(newAST),
3264
- schema: (0, buildASTSchema_1.buildASTSchema)(newAST, { addInvalidExtensionOrphans: true, assumeValid: true, assumeValidSDL: true }),
3265
3228
  success: true,
3266
3229
  warnings: this.warnings,
3267
3230
  };
3268
3231
  }
3269
3232
  }
3270
3233
  exports.NormalizationFactory = NormalizationFactory;
3271
- function batchNormalize({ options, subgraphs }) {
3272
- const authorizationDataByParentTypeName = new Map();
3273
- const concreteTypeNamesByAbstractTypeName = new Map();
3274
- const entityDataByTypeName = new Map();
3275
- const interfaceImplementationTypeNamesByInterfaceTypeName = new Map();
3276
- const internalSubgraphBySubgraphName = new Map();
3277
- const allOverridesByTargetSubgraphName = new Map();
3278
- const overrideSourceSubgraphNamesByFieldPath = new Map();
3279
- const duplicateOverriddenFieldPaths = new Set();
3280
- const parentDefinitionDataMapsBySubgraphName = new Map();
3281
- const subgraphNames = new Set();
3282
- const nonUniqueSubgraphNames = new Set();
3283
- const invalidNameErrorMessages = [];
3284
- const invalidORScopesCoords = new Set();
3285
- const fieldCoordsByNamedTypeName = new Map();
3286
- const warnings = [];
3287
- const validationErrors = [];
3288
- // Record the subgraph names first, so that subgraph references can be validated
3289
- for (const subgraph of subgraphs) {
3290
- if (subgraph.name) {
3291
- (0, subgraph_1.recordSubgraphName)(subgraph.name, subgraphNames, nonUniqueSubgraphNames);
3292
- }
3293
- }
3294
- const internalGraph = new graph_1.Graph();
3295
- for (let i = 0; i < subgraphs.length; i++) {
3296
- const subgraph = subgraphs[i];
3297
- const subgraphName = subgraph.name || `subgraph-${i}-${Date.now()}`;
3298
- if (!subgraph.name) {
3299
- invalidNameErrorMessages.push((0, errors_1.invalidSubgraphNameErrorMessage)(i, subgraphName));
3300
- }
3301
- const normalizationResult = normalizeSubgraph({
3302
- document: subgraph.definitions,
3303
- internalGraph,
3304
- options,
3305
- subgraphName,
3306
- });
3307
- if (normalizationResult.warnings.length > 0) {
3308
- warnings.push(...normalizationResult.warnings);
3309
- }
3310
- if (!normalizationResult.success) {
3311
- validationErrors.push((0, errors_1.subgraphValidationError)(subgraphName, normalizationResult.errors));
3312
- continue;
3313
- }
3314
- if (!normalizationResult) {
3315
- validationErrors.push((0, errors_1.subgraphValidationError)(subgraphName, [errors_1.subgraphValidationFailureError]));
3316
- continue;
3317
- }
3318
- parentDefinitionDataMapsBySubgraphName.set(subgraphName, normalizationResult.parentDefinitionDataByTypeName);
3319
- for (const authorizationData of normalizationResult.authorizationDataByParentTypeName.values()) {
3320
- (0, utils_3.upsertAuthorizationData)(authorizationDataByParentTypeName, authorizationData, invalidORScopesCoords);
3321
- }
3322
- for (const [namedTypeName, fieldCoords] of normalizationResult.fieldCoordsByNamedTypeName) {
3323
- (0, utils_5.addIterableToSet)({
3324
- source: fieldCoords,
3325
- target: (0, utils_5.getValueOrDefault)(fieldCoordsByNamedTypeName, namedTypeName, () => new Set()),
3326
- });
3327
- }
3328
- for (const [abstractTypeName, incomingConcreteTypeNames,] of normalizationResult.concreteTypeNamesByAbstractTypeName) {
3329
- const existingConcreteTypeNames = concreteTypeNamesByAbstractTypeName.get(abstractTypeName);
3330
- if (!existingConcreteTypeNames) {
3331
- concreteTypeNamesByAbstractTypeName.set(abstractTypeName, new Set(incomingConcreteTypeNames));
3332
- continue;
3333
- }
3334
- (0, utils_5.addIterableToSet)({
3335
- source: incomingConcreteTypeNames,
3336
- target: existingConcreteTypeNames,
3337
- });
3338
- }
3339
- for (const [interfaceTypeName, incomingInterfaceTypeNames,] of normalizationResult.interfaceImplementationTypeNamesByInterfaceTypeName) {
3340
- const existingInterfaceTypeNames = interfaceImplementationTypeNamesByInterfaceTypeName.get(interfaceTypeName);
3341
- if (!existingInterfaceTypeNames) {
3342
- interfaceImplementationTypeNamesByInterfaceTypeName.set(interfaceTypeName, new Set(incomingInterfaceTypeNames));
3343
- continue;
3344
- }
3345
- (0, utils_5.addIterableToSet)({
3346
- source: incomingInterfaceTypeNames,
3347
- target: existingInterfaceTypeNames,
3348
- });
3349
- }
3350
- for (const [typeName, entityData] of normalizationResult.entityDataByTypeName) {
3351
- const keyFieldSetDataByFieldSet = entityData.keyFieldSetDatasBySubgraphName.get(subgraphName);
3352
- if (!keyFieldSetDataByFieldSet) {
3353
- continue;
3354
- }
3355
- (0, utils_3.upsertEntityData)({
3356
- entityDataByTypeName,
3357
- keyFieldSetDataByFieldSet,
3358
- typeName,
3359
- subgraphName,
3360
- });
3361
- }
3362
- if (subgraph.name) {
3363
- internalSubgraphBySubgraphName.set(subgraphName, {
3364
- conditionalFieldDataByCoordinates: normalizationResult.conditionalFieldDataByCoordinates,
3365
- configurationDataByTypeName: normalizationResult.configurationDataByTypeName,
3366
- costs: normalizationResult.costs,
3367
- definitions: normalizationResult.subgraphAST,
3368
- directiveDefinitionByName: normalizationResult.directiveDefinitionByName,
3369
- entityInterfaces: normalizationResult.entityInterfaces,
3370
- isVersionTwo: normalizationResult.isVersionTwo,
3371
- keyFieldNamesByParentTypeName: normalizationResult.keyFieldNamesByParentTypeName,
3372
- name: subgraphName,
3373
- operationTypes: normalizationResult.operationTypes,
3374
- overriddenFieldNamesByParentTypeName: new Map(),
3375
- parentDefinitionDataByTypeName: normalizationResult.parentDefinitionDataByTypeName,
3376
- persistedDirectiveDefinitionDataByDirectiveName: normalizationResult.persistedDirectiveDefinitionDataByDirectiveName,
3377
- schema: normalizationResult.schema,
3378
- schemaNode: normalizationResult.schemaNode,
3379
- url: subgraph.url,
3380
- });
3381
- }
3382
- if (normalizationResult.overridesByTargetSubgraphName.size < 1) {
3383
- continue;
3384
- }
3385
- for (const [targetSubgraphName, overridesData] of normalizationResult.overridesByTargetSubgraphName) {
3386
- const isTargetValid = subgraphNames.has(targetSubgraphName);
3387
- for (const [parentTypeName, fieldNames] of overridesData) {
3388
- /* It's possible for a renamed root type to have a field overridden, so make sure any errors at this stage are
3389
- propagated with the original typename. */
3390
- const originalParentTypeName = normalizationResult.originalTypeNameByRenamedTypeName.get(parentTypeName) || parentTypeName;
3391
- if (!isTargetValid) {
3392
- warnings.push((0, warnings_1.invalidOverrideTargetSubgraphNameWarning)(targetSubgraphName, originalParentTypeName, [...fieldNames], subgraph.name));
3393
- }
3394
- else {
3395
- const overridesData = (0, utils_5.getValueOrDefault)(allOverridesByTargetSubgraphName, targetSubgraphName, () => new Map());
3396
- const existingFieldNames = (0, utils_5.getValueOrDefault)(overridesData, parentTypeName, () => new Set(fieldNames));
3397
- (0, utils_5.addIterableToSet)({
3398
- source: fieldNames,
3399
- target: existingFieldNames,
3400
- });
3401
- }
3402
- for (const fieldName of fieldNames) {
3403
- const fieldCoords = `${originalParentTypeName}.${fieldName}`;
3404
- const sourceSubgraphs = overrideSourceSubgraphNamesByFieldPath.get(fieldCoords);
3405
- if (!sourceSubgraphs) {
3406
- overrideSourceSubgraphNamesByFieldPath.set(fieldCoords, [subgraphName]);
3407
- continue;
3408
- }
3409
- sourceSubgraphs.push(subgraphName);
3410
- duplicateOverriddenFieldPaths.add(fieldCoords);
3411
- }
3412
- }
3413
- }
3414
- }
3415
- const allErrors = [];
3416
- if (invalidORScopesCoords.size > 0) {
3417
- allErrors.push((0, errors_1.orScopesLimitError)(constants_1.MAX_OR_SCOPES, [...invalidORScopesCoords]));
3418
- }
3419
- if (invalidNameErrorMessages.length > 0 || nonUniqueSubgraphNames.size > 0) {
3420
- allErrors.push((0, errors_1.invalidSubgraphNamesError)([...nonUniqueSubgraphNames], invalidNameErrorMessages));
3421
- }
3422
- if (duplicateOverriddenFieldPaths.size > 0) {
3423
- const duplicateOverriddenFieldErrorMessages = [];
3424
- for (const fieldPath of duplicateOverriddenFieldPaths) {
3425
- const sourceSubgraphNames = (0, utils_5.getOrThrowError)(overrideSourceSubgraphNamesByFieldPath, fieldPath, 'overrideSourceSubgraphNamesByFieldPath');
3426
- duplicateOverriddenFieldErrorMessages.push((0, errors_1.duplicateOverriddenFieldErrorMessage)(fieldPath, sourceSubgraphNames));
3427
- }
3428
- allErrors.push((0, errors_1.duplicateOverriddenFieldsError)(duplicateOverriddenFieldErrorMessages));
3429
- }
3430
- allErrors.push(...validationErrors);
3431
- if (allErrors.length > 0) {
3432
- return {
3433
- errors: allErrors,
3434
- success: false,
3435
- warnings,
3436
- };
3437
- }
3438
- for (const [targetSubgraphName, overridesData] of allOverridesByTargetSubgraphName) {
3439
- const internalSubgraph = (0, utils_5.getOrThrowError)(internalSubgraphBySubgraphName, targetSubgraphName, 'internalSubgraphBySubgraphName');
3440
- internalSubgraph.overriddenFieldNamesByParentTypeName = overridesData;
3441
- for (const [parentTypeName, fieldNames] of overridesData) {
3442
- const configurationData = internalSubgraph.configurationDataByTypeName.get(parentTypeName);
3443
- if (!configurationData) {
3444
- continue;
3445
- }
3446
- (0, utils_3.subtractSet)(fieldNames, configurationData.fieldNames);
3447
- if (configurationData.fieldNames.size < 1) {
3448
- internalSubgraph.configurationDataByTypeName.delete(parentTypeName);
3449
- }
3450
- }
3451
- }
3452
- return {
3453
- authorizationDataByParentTypeName,
3454
- concreteTypeNamesByAbstractTypeName,
3455
- entityDataByTypeName,
3456
- fieldCoordsByNamedTypeName,
3457
- interfaceImplementationTypeNamesByInterfaceTypeName,
3458
- internalSubgraphBySubgraphName: internalSubgraphBySubgraphName,
3459
- internalGraph,
3460
- success: true,
3461
- warnings,
3462
- };
3463
- }
3464
3234
  //# sourceMappingURL=normalization-factory.js.map