@wundergraph/composition 0.18.4 → 0.19.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/dist/ast/utils.d.ts +2 -9
  2. package/dist/ast/utils.js +2 -73
  3. package/dist/ast/utils.js.map +1 -1
  4. package/dist/errors/errors.d.ts +13 -19
  5. package/dist/errors/errors.js +50 -67
  6. package/dist/errors/errors.js.map +1 -1
  7. package/dist/federation/federation-factory.d.ts +17 -46
  8. package/dist/federation/federation-factory.js +391 -1002
  9. package/dist/federation/federation-factory.js.map +1 -1
  10. package/dist/federation/utils.d.ts +1 -115
  11. package/dist/federation/utils.js +0 -29
  12. package/dist/federation/utils.js.map +1 -1
  13. package/dist/federation/walkers.d.ts +3 -0
  14. package/dist/federation/walkers.js +120 -0
  15. package/dist/federation/walkers.js.map +1 -0
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +2 -1
  18. package/dist/index.js.map +1 -1
  19. package/dist/normalization/normalization-factory.d.ts +26 -18
  20. package/dist/normalization/normalization-factory.js +139 -141
  21. package/dist/normalization/normalization-factory.js.map +1 -1
  22. package/dist/normalization/utils.js +53 -54
  23. package/dist/normalization/utils.js.map +1 -1
  24. package/dist/normalization/walkers.js +156 -128
  25. package/dist/normalization/walkers.js.map +1 -1
  26. package/dist/router-configuration/router-configuration.d.ts +0 -1
  27. package/dist/schema-building/ast.d.ts +17 -5
  28. package/dist/schema-building/ast.js +32 -17
  29. package/dist/schema-building/ast.js.map +1 -1
  30. package/dist/schema-building/type-definition-data.d.ts +51 -25
  31. package/dist/schema-building/type-extension-data.d.ts +11 -7
  32. package/dist/schema-building/type-merging.d.ts +2 -4
  33. package/dist/schema-building/type-merging.js +8 -27
  34. package/dist/schema-building/type-merging.js.map +1 -1
  35. package/dist/schema-building/utils.d.ts +41 -18
  36. package/dist/schema-building/utils.js +855 -111
  37. package/dist/schema-building/utils.js.map +1 -1
  38. package/dist/subgraph/subgraph.d.ts +8 -10
  39. package/dist/subgraph/subgraph.js +1 -237
  40. package/dist/subgraph/subgraph.js.map +1 -1
  41. package/dist/tsconfig.tsbuildinfo +1 -1
  42. package/dist/utils/constants.d.ts +8 -1
  43. package/dist/utils/constants.js +47 -19
  44. package/dist/utils/constants.js.map +1 -1
  45. package/dist/utils/string-constants.d.ts +10 -4
  46. package/dist/utils/string-constants.js +20 -6
  47. package/dist/utils/string-constants.js.map +1 -1
  48. package/dist/utils/utils.d.ts +4 -4
  49. package/dist/utils/utils.js +10 -4
  50. package/dist/utils/utils.js.map +1 -1
  51. package/package.json +4 -3
  52. package/dist/ast/ast.d.ts +0 -97
  53. package/dist/ast/ast.js +0 -168
  54. package/dist/ast/ast.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.removeInheritableDirectivesFromParentWithFieldsData = exports.getUnionNodeByData = exports.getSchemaNodeByData = exports.getScalarNodeByData = exports.getParentWithFieldsNodeByData = exports.getInputObjectNodeByData = exports.getEnumNodeByData = exports.extractImplementedInterfaceTypeNames = exports.convertKindForExtension = exports.isTypeNameRootType = exports.upsertUnionExtensionDataByNode = exports.upsertUnionDefinitionDataByNode = exports.extractUniqueUnionMembers = exports.upsertScalarExtensionDataByNode = exports.upsertScalarDefinitionDataByNode = exports.upsertObjectDefinitionDataByNode = exports.upsertInterfaceDefinitionDataByNode = exports.upsertInputValueDataByNode = exports.upsertInputObjectExtensionDataByNode = exports.upsertInputObjectDefinitionDataByNode = exports.upsertExtensionWithFieldsDataByNode = exports.upsertFieldDataByNode = exports.addInheritedDirectivesToFieldData = exports.upsertEnumValueDataByNode = exports.upsertEnumExtensionDataByNode = exports.upsertEnumDefinitionDataByNode = exports.upsertArgumentDataByNode = exports.extractArguments = exports.extractDirectives = exports.getDirectiveValidationErrors = exports.getDefinedArgumentsForDirective = exports.isNodeExternalOrShareable = void 0;
3
+ exports.isTypeValidImplementation = exports.MergeMethod = exports.isFieldExternalInAllMutualSubgraphs = exports.isShareabilityOfAllFieldInstancesValid = exports.addValidPersistedDirectiveDefinitionNodeByData = exports.getValidFieldArgumentNodes = exports.getNodeWithPersistedDirectivesByInputValueData = exports.getNodeWithPersistedDirectivesByFieldData = exports.getNodeWithPersistedDirectivesByData = exports.upsertValidObjectExtensionData = exports.pushAuthorizationDirectives = exports.upsertObjectExtensionData = exports.upsertParentDefinitionData = exports.removeInheritableDirectivesFromParentWithFieldsData = exports.getUnionNodeByData = exports.getSchemaNodeByData = exports.getScalarNodeByData = exports.getParentWithFieldsNodeByData = exports.getInputObjectNodeByData = exports.getEnumNodeByData = exports.extractImplementedInterfaceTypeNames = exports.convertKindForExtension = exports.getRenamedRootTypeName = exports.isTypeNameRootType = exports.addUnionExtensionDataByNode = exports.addUnionDefinitionDataByNode = exports.extractUniqueUnionMembers = exports.addScalarExtensionDataByNode = exports.addScalarDefinitionDataByNode = exports.upsertPersistedDirectiveDefinitionData = exports.addPersistedDirectiveDefinitionDataByNode = exports.addObjectDefinitionDataByNode = exports.addInterfaceDefinitionDataByNode = exports.addInputValueDataByNode = exports.addInputObjectExtensionDataByNode = exports.addInputObjectDefinitionDataByNode = exports.addExtensionWithFieldsDataByNode = exports.addFieldDataByNode = exports.addInheritedDirectivesToFieldData = exports.addEnumValueDataByNode = exports.addEnumExtensionDataByNode = exports.addEnumDefinitionDataByNode = exports.isTypeRequired = exports.extractArguments = exports.extractDirectives = exports.getDirectiveValidationErrors = exports.getDefinedArgumentsForDirective = exports.isNodeExternalOrShareable = void 0;
4
4
  const graphql_1 = require("graphql");
5
5
  const ast_1 = require("./ast");
6
6
  const utils_1 = require("../ast/utils");
@@ -10,6 +10,15 @@ const type_merging_1 = require("./type-merging");
10
10
  const utils_2 = require("../normalization/utils");
11
11
  const utils_3 = require("../utils/utils");
12
12
  const constants_1 = require("../utils/constants");
13
+ const merge_1 = require("@graphql-tools/merge");
14
+ function newPersistedDirectivesData() {
15
+ return {
16
+ deprecatedReason: '',
17
+ directives: new Map(),
18
+ isDeprecated: false,
19
+ tags: new Map(),
20
+ };
21
+ }
13
22
  function isNodeExternalOrShareable(node, areAllFieldsShareable, directivesByDirectiveName) {
14
23
  const result = {
15
24
  isExternal: directivesByDirectiveName.has(string_constants_1.EXTERNAL),
@@ -141,13 +150,14 @@ function extractDirectives(node, directivesByDirectiveName, errors, directiveDef
141
150
  return directivesByDirectiveName;
142
151
  }
143
152
  exports.extractDirectives = extractDirectives;
144
- function extractArguments(argumentDataByArgumentName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentsWithChildArguments, parentTypeName, subgraphName) {
153
+ function extractArguments(argumentDataByArgumentName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentsWithChildArguments, originalParentTypeName, renamedParentTypeName, subgraphName) {
145
154
  if (!node.arguments?.length) {
146
155
  return argumentDataByArgumentName;
147
156
  }
148
157
  const fieldName = node.name.value;
149
- const fieldPath = `${parentTypeName}.${fieldName}`;
150
- parentsWithChildArguments.add(parentTypeName);
158
+ const originalFieldPath = `${originalParentTypeName}.${fieldName}`;
159
+ const renamedFieldPath = `${renamedParentTypeName}.${fieldName}`;
160
+ parentsWithChildArguments.add(originalParentTypeName);
151
161
  const duplicatedArguments = new Set();
152
162
  for (const argumentNode of node.arguments) {
153
163
  const argumentName = argumentNode.name.value;
@@ -155,53 +165,88 @@ function extractArguments(argumentDataByArgumentName, node, errors, directiveDef
155
165
  duplicatedArguments.add(argumentName);
156
166
  continue;
157
167
  }
158
- upsertArgumentDataByNode(argumentDataByArgumentName, argumentNode, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentTypeName, fieldName, subgraphName);
168
+ addInputValueDataByNode(argumentDataByArgumentName, argumentNode, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, `${originalFieldPath}(${argumentName}: ...)`, subgraphName, errors, `${renamedFieldPath}(${argumentName}: ...)`);
159
169
  }
160
170
  if (duplicatedArguments.size > 0) {
161
- errors.push((0, errors_1.duplicateArgumentsError)(fieldPath, [...duplicatedArguments]));
171
+ errors.push((0, errors_1.duplicateArgumentsError)(originalFieldPath, [...duplicatedArguments]));
162
172
  }
163
173
  return argumentDataByArgumentName;
164
174
  }
165
175
  exports.extractArguments = extractArguments;
166
- function upsertArgumentDataByNode(argumentDataByArgumentName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentTypeName, fieldName, subgraphName) {
167
- const name = node.name.value;
168
- const hostPath = `${parentTypeName}.${fieldName}`;
169
- argumentDataByArgumentName.set(name, {
170
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, `${hostPath}(${name}: ...)`, true),
171
- name,
172
- node: (0, ast_1.getMutableInputValueNode)(node, parentTypeName, fieldName),
173
- requiredSubgraphNames: new Set([subgraphName]),
174
- subgraphNames: new Set([subgraphName]),
175
- type: (0, ast_1.getMutableTypeNode)(node.type, hostPath),
176
- defaultValue: node.defaultValue,
177
- description: (0, utils_1.formatDescription)(node.description),
178
- });
176
+ function isTypeRequired(node) {
177
+ return node.kind === graphql_1.Kind.NON_NULL_TYPE;
179
178
  }
180
- exports.upsertArgumentDataByNode = upsertArgumentDataByNode;
181
- function upsertEnumDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
182
- const typeName = node.name.value;
183
- parentDefinitionDataByTypeName.set(typeName, {
179
+ exports.isTypeRequired = isTypeRequired;
180
+ // TODO replace naïve comparison
181
+ function areDefaultValuesCompatible(typeNode, incomingDefaultValue) {
182
+ switch (typeNode.kind) {
183
+ case graphql_1.Kind.LIST_TYPE:
184
+ return incomingDefaultValue.kind === graphql_1.Kind.LIST || incomingDefaultValue.kind === graphql_1.Kind.NULL;
185
+ case graphql_1.Kind.NAMED_TYPE:
186
+ if (incomingDefaultValue.kind === graphql_1.Kind.NULL) {
187
+ return true;
188
+ }
189
+ switch (typeNode.name.value) {
190
+ case string_constants_1.BOOLEAN_SCALAR:
191
+ return incomingDefaultValue.kind === graphql_1.Kind.BOOLEAN;
192
+ case string_constants_1.FLOAT_SCALAR:
193
+ return incomingDefaultValue.kind === graphql_1.Kind.INT || incomingDefaultValue.kind === graphql_1.Kind.FLOAT;
194
+ case string_constants_1.INT_SCALAR:
195
+ return incomingDefaultValue.kind === graphql_1.Kind.INT;
196
+ case string_constants_1.STRING_SCALAR:
197
+ return incomingDefaultValue.kind === graphql_1.Kind.STRING;
198
+ default:
199
+ return true;
200
+ }
201
+ case graphql_1.Kind.NON_NULL_TYPE:
202
+ if (incomingDefaultValue.kind === graphql_1.Kind.NULL) {
203
+ return false;
204
+ }
205
+ return areDefaultValuesCompatible(typeNode.type, incomingDefaultValue);
206
+ }
207
+ }
208
+ function compareAndValidateInputValueDefaultValues(existingData, incomingData, errors) {
209
+ if (!existingData.defaultValue) {
210
+ // TODO warning if default value in incoming
211
+ return;
212
+ }
213
+ if (!incomingData.defaultValue) {
214
+ // TODO warning
215
+ existingData.includeDefaultValue = false;
216
+ return;
217
+ }
218
+ const existingDefaultValueString = (0, graphql_1.print)(existingData.defaultValue);
219
+ const incomingDefaultValueString = (0, graphql_1.print)(incomingData.defaultValue);
220
+ if (existingDefaultValueString !== incomingDefaultValueString) {
221
+ errors.push((0, errors_1.incompatibleInputValueDefaultValuesError)(`${existingData.isArgument ? 'argument' : 'input value'} "${existingData.name}"`, existingData.originalPath, [...incomingData.subgraphNames], existingDefaultValueString, incomingDefaultValueString));
222
+ return;
223
+ }
224
+ }
225
+ function addEnumDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
226
+ const name = node.name.value;
227
+ parentDefinitionDataByTypeName.set(name, {
184
228
  appearances: 1,
185
229
  directivesByDirectiveName,
230
+ enumValueDataByValueName: new Map(),
186
231
  kind: node.kind,
187
232
  node: (0, ast_1.getMutableEnumNode)(node),
188
- typeName,
189
- enumValueDataByValueName: new Map(),
233
+ persistedDirectivesData: newPersistedDirectivesData(),
234
+ name,
190
235
  description: (0, utils_1.formatDescription)(node.description),
191
236
  });
192
237
  }
193
- exports.upsertEnumDefinitionDataByNode = upsertEnumDefinitionDataByNode;
194
- function upsertEnumExtensionDataByNode(parentExtensionDataByTypeName, node, directivesByDirectiveName) {
195
- const typeName = node.name.value;
196
- parentExtensionDataByTypeName.set(typeName, {
238
+ exports.addEnumDefinitionDataByNode = addEnumDefinitionDataByNode;
239
+ function addEnumExtensionDataByNode(parentExtensionDataByTypeName, node, directivesByDirectiveName) {
240
+ const name = node.name.value;
241
+ parentExtensionDataByTypeName.set(name, {
197
242
  directivesByDirectiveName,
198
243
  enumValueDataByValueName: new Map(),
199
244
  kind: node.kind,
200
- typeName,
245
+ name,
201
246
  });
202
247
  }
203
- exports.upsertEnumExtensionDataByNode = upsertEnumExtensionDataByNode;
204
- function upsertEnumValueDataByNode(enumValueDataByValueName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentTypeName) {
248
+ exports.addEnumExtensionDataByNode = addEnumExtensionDataByNode;
249
+ function addEnumValueDataByNode(enumValueDataByValueName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentTypeName) {
205
250
  const name = node.name.value;
206
251
  enumValueDataByValueName.set(name, {
207
252
  appearances: 1,
@@ -209,10 +254,11 @@ function upsertEnumValueDataByNode(enumValueDataByValueName, node, errors, direc
209
254
  name,
210
255
  node: (0, ast_1.getMutableEnumValueNode)(node),
211
256
  parentTypeName,
257
+ persistedDirectivesData: newPersistedDirectivesData(),
212
258
  description: (0, utils_1.formatDescription)(node.description),
213
259
  });
214
260
  }
215
- exports.upsertEnumValueDataByNode = upsertEnumValueDataByNode;
261
+ exports.addEnumValueDataByNode = addEnumValueDataByNode;
216
262
  function addInheritedDirectivesToFieldData(parentDirectivesByDirectiveName, fieldDirectivesByDirectiveName) {
217
263
  for (const directiveName of constants_1.INHERITABLE_DIRECTIVE_NAMES) {
218
264
  if (parentDirectivesByDirectiveName.get(directiveName)) {
@@ -222,139 +268,233 @@ function addInheritedDirectivesToFieldData(parentDirectivesByDirectiveName, fiel
222
268
  return fieldDirectivesByDirectiveName;
223
269
  }
224
270
  exports.addInheritedDirectivesToFieldData = addInheritedDirectivesToFieldData;
225
- function upsertFieldDataByNode(fieldDataByFieldName, node, errors, argumentDataByArgumentName, directivesByDirectiveName, parentTypeName, subgraphName, isSubgraphVersionTwo) {
271
+ function addFieldDataByNode(fieldDataByFieldName, node, errors, argumentDataByArgumentName, directivesByDirectiveName, originalParentTypeName, renamedParentTypeName, subgraphName, isSubgraphVersionTwo) {
226
272
  const name = node.name.value;
227
- const fieldPath = `${parentTypeName}.${name}`;
273
+ const fieldPath = `${originalParentTypeName}.${name}`;
228
274
  const isNodeExternalOrShareableResult = isNodeExternalOrShareable(node, !isSubgraphVersionTwo, directivesByDirectiveName);
229
275
  const fieldData = {
230
276
  argumentDataByArgumentName: argumentDataByArgumentName,
231
277
  isExternalBySubgraphName: new Map([[subgraphName, isNodeExternalOrShareableResult.isExternal]]),
278
+ isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
232
279
  isShareableBySubgraphName: new Map([[subgraphName, isNodeExternalOrShareableResult.isShareable]]),
233
- node: (0, ast_1.getMutableFieldNode)(node, parentTypeName),
280
+ node: (0, ast_1.getMutableFieldNode)(node, fieldPath),
234
281
  name,
235
- namedTypeName: (0, type_merging_1.getNamedTypeForChild)(fieldPath, node.type),
236
- parentTypeName,
282
+ namedTypeName: (0, ast_1.getTypeNodeNamedTypeName)(node.type),
283
+ originalParentTypeName,
284
+ persistedDirectivesData: newPersistedDirectivesData(),
285
+ renamedParentTypeName,
237
286
  subgraphNames: new Set([subgraphName]),
287
+ type: (0, ast_1.getMutableTypeNode)(node.type, fieldPath),
238
288
  directivesByDirectiveName,
239
289
  description: (0, utils_1.formatDescription)(node.description),
240
290
  };
241
291
  fieldDataByFieldName.set(name, fieldData);
242
292
  return fieldData;
243
293
  }
244
- exports.upsertFieldDataByNode = upsertFieldDataByNode;
245
- function upsertExtensionWithFieldsDataByNode(parentExtensionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity) {
246
- const typeName = node.name.value;
294
+ exports.addFieldDataByNode = addFieldDataByNode;
295
+ function addExtensionWithFieldsDataByNode(parentExtensionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, isRootType, subgraphName, renamedTypeName) {
296
+ const name = node.name.value;
247
297
  const kind = convertKindForExtension(node);
248
298
  switch (kind) {
249
299
  case graphql_1.Kind.INTERFACE_TYPE_EXTENSION:
250
- parentExtensionDataByTypeName.set(typeName, {
251
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
300
+ parentExtensionDataByTypeName.set(name, {
301
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
252
302
  fieldDataByFieldName: new Map(),
253
303
  implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
254
304
  isEntity,
255
305
  kind,
256
- typeName,
306
+ name,
257
307
  });
258
308
  return;
259
309
  default:
260
- parentExtensionDataByTypeName.set(typeName, {
261
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
310
+ parentExtensionDataByTypeName.set(name, {
311
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
262
312
  fieldDataByFieldName: new Map(),
263
313
  implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
264
314
  isEntity,
315
+ isRootType,
265
316
  kind,
317
+ name,
266
318
  node: (0, ast_1.getMutableObjectExtensionNode)(node),
267
- typeName,
319
+ persistedDirectivesData: newPersistedDirectivesData(),
320
+ renamedTypeName: renamedTypeName || name,
321
+ subgraphNames: new Set([subgraphName]),
268
322
  });
269
323
  }
270
324
  }
271
- exports.upsertExtensionWithFieldsDataByNode = upsertExtensionWithFieldsDataByNode;
272
- function upsertInputObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath) {
273
- const typeName = node.name.value;
274
- parentDefinitionDataByTypeName.set(typeName, {
275
- appearances: 1,
276
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
325
+ exports.addExtensionWithFieldsDataByNode = addExtensionWithFieldsDataByNode;
326
+ function addInputObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, subgraphName, errors) {
327
+ const name = node.name.value;
328
+ parentDefinitionDataByTypeName.set(name, {
329
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
277
330
  inputValueDataByValueName: new Map(),
278
331
  kind: node.kind,
279
332
  node: (0, ast_1.getMutableInputObjectNode)(node),
280
- typeName,
333
+ persistedDirectivesData: newPersistedDirectivesData(),
334
+ name,
335
+ subgraphNames: new Set([subgraphName]),
281
336
  description: (0, utils_1.formatDescription)(node.description),
282
337
  });
283
338
  }
284
- exports.upsertInputObjectDefinitionDataByNode = upsertInputObjectDefinitionDataByNode;
285
- function upsertInputObjectExtensionDataByNode(parentExtensionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath) {
286
- const typeName = node.name.value;
287
- parentExtensionDataByTypeName.set(typeName, {
288
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
339
+ exports.addInputObjectDefinitionDataByNode = addInputObjectDefinitionDataByNode;
340
+ function addInputObjectExtensionDataByNode(parentExtensionDataByTypeName, node, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, errors) {
341
+ const name = node.name.value;
342
+ parentExtensionDataByTypeName.set(name, {
343
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
289
344
  inputValueDataByValueName: new Map(),
290
345
  kind: node.kind,
291
- typeName,
346
+ name,
292
347
  });
293
348
  }
294
- exports.upsertInputObjectExtensionDataByNode = upsertInputObjectExtensionDataByNode;
295
- function upsertInputValueDataByNode(inputValueDataByValueName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, parentTypeName) {
349
+ exports.addInputObjectExtensionDataByNode = addInputObjectExtensionDataByNode;
350
+ function addInputValueDataByNode(inputValueDataByValueName, node, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, originalPath, subgraphName, errors, renamedPath) {
296
351
  const name = node.name.value;
352
+ // Only arguments have renamed paths
353
+ const isArgument = !!renamedPath;
354
+ if (node.defaultValue && !areDefaultValuesCompatible(node.type, node.defaultValue)) {
355
+ errors.push((0, errors_1.incompatibleInputValueDefaultValueTypeError)((isArgument ? 'argument' : 'input field') + ` "${name}"`, originalPath, (0, merge_1.printTypeNode)(node.type), (0, graphql_1.print)(node.defaultValue)));
356
+ }
297
357
  inputValueDataByValueName.set(name, {
298
- appearances: 1,
299
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, `${parentTypeName}.${name}`),
358
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, originalPath, isArgument),
359
+ includeDefaultValue: !!node.defaultValue,
360
+ isArgument,
300
361
  name,
301
- node: (0, ast_1.getMutableInputValueNode)(node, parentTypeName, name),
302
- parentTypeName,
362
+ node: (0, ast_1.getMutableInputValueNode)(node, originalPath),
363
+ originalPath,
364
+ persistedDirectivesData: newPersistedDirectivesData(),
365
+ renamedPath: renamedPath || originalPath,
366
+ requiredSubgraphNames: new Set(isTypeRequired(node.type) ? [subgraphName] : []),
367
+ subgraphNames: new Set([subgraphName]),
368
+ type: (0, ast_1.getMutableTypeNode)(node.type, originalPath),
369
+ defaultValue: node.defaultValue,
303
370
  description: (0, utils_1.formatDescription)(node.description),
304
371
  });
305
372
  }
306
- exports.upsertInputValueDataByNode = upsertInputValueDataByNode;
307
- function upsertInterfaceDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, subgraphName) {
308
- const typeName = node.name.value;
309
- parentDefinitionDataByTypeName.set(typeName, {
310
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
373
+ exports.addInputValueDataByNode = addInputValueDataByNode;
374
+ function addInterfaceDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, subgraphName) {
375
+ const name = node.name.value;
376
+ parentDefinitionDataByTypeName.set(name, {
377
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
311
378
  fieldDataByFieldName: new Map(),
312
379
  isEntity,
313
380
  implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
314
381
  kind: node.kind,
315
382
  node: (0, ast_1.getMutableInterfaceNode)(node),
383
+ persistedDirectivesData: newPersistedDirectivesData(),
316
384
  subgraphNames: new Set([subgraphName]),
317
- typeName,
385
+ name,
318
386
  description: (0, utils_1.formatDescription)(node.description),
319
387
  });
320
388
  }
321
- exports.upsertInterfaceDefinitionDataByNode = upsertInterfaceDefinitionDataByNode;
322
- function upsertObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, isRootType, subgraphName) {
323
- const typeName = node.name.value;
324
- parentDefinitionDataByTypeName.set(typeName, {
325
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
389
+ exports.addInterfaceDefinitionDataByNode = addInterfaceDefinitionDataByNode;
390
+ function addObjectDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, isEntity, isRootType, subgraphName, renamedTypeName) {
391
+ const name = node.name.value;
392
+ parentDefinitionDataByTypeName.set(name, {
393
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
326
394
  fieldDataByFieldName: new Map(),
327
395
  isEntity,
328
396
  isRootType,
329
397
  implementedInterfaceTypeNames: extractImplementedInterfaceTypeNames(node, new Set(), errors),
330
398
  kind: node.kind,
399
+ name,
331
400
  node: (0, ast_1.getMutableObjectNode)(node),
401
+ persistedDirectivesData: newPersistedDirectivesData(),
402
+ renamedTypeName: renamedTypeName || name,
403
+ subgraphNames: new Set([subgraphName]),
404
+ description: (0, utils_1.formatDescription)(node.description),
405
+ });
406
+ }
407
+ exports.addObjectDefinitionDataByNode = addObjectDefinitionDataByNode;
408
+ function addPersistedDirectiveDefinitionDataByNode(persistedDirectiveDefinitionDataByDirectiveName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, executableLocations, subgraphName) {
409
+ const name = node.name.value;
410
+ const argumentDataByArgumentName = new Map();
411
+ for (const argumentNode of node.arguments || []) {
412
+ const originalPath = `@${name}(${argumentNode.name.value}: ...)`;
413
+ addInputValueDataByNode(argumentDataByArgumentName, argumentNode, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, originalPath, subgraphName, errors, originalPath);
414
+ }
415
+ persistedDirectiveDefinitionDataByDirectiveName.set(name, {
416
+ argumentDataByArgumentName,
417
+ executableLocations,
418
+ name: name,
419
+ repeatable: node.repeatable,
332
420
  subgraphNames: new Set([subgraphName]),
333
- typeName,
334
421
  description: (0, utils_1.formatDescription)(node.description),
335
422
  });
336
423
  }
337
- exports.upsertObjectDefinitionDataByNode = upsertObjectDefinitionDataByNode;
338
- function upsertScalarDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
339
- const typeName = node.name.value;
340
- parentDefinitionDataByTypeName.set(typeName, {
424
+ exports.addPersistedDirectiveDefinitionDataByNode = addPersistedDirectiveDefinitionDataByNode;
425
+ function setMutualExecutableLocations(persistedDirectiveDefinitionData, incomingExecutableLocations) {
426
+ const mutualExecutableLocations = new Set();
427
+ for (const incomingExecutableLocation of incomingExecutableLocations) {
428
+ if (persistedDirectiveDefinitionData.executableLocations.has(incomingExecutableLocation)) {
429
+ mutualExecutableLocations.add(incomingExecutableLocation);
430
+ }
431
+ }
432
+ persistedDirectiveDefinitionData.executableLocations = mutualExecutableLocations;
433
+ }
434
+ function upsertPersistedDirectiveDefinitionData(persistedDirectiveDefinitionDataByDirectiveName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedInputValueTypeNames, subgraphNumber, errors) {
435
+ const name = incomingData.name;
436
+ const existingData = persistedDirectiveDefinitionDataByDirectiveName.get(name);
437
+ if (!existingData) {
438
+ // The executable directive must be defined in all subgraphs to be persisted.
439
+ if (subgraphNumber > 1) {
440
+ return;
441
+ }
442
+ const argumentDataByArgumentName = new Map();
443
+ for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
444
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
445
+ upsertInputValueData(argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
446
+ }
447
+ persistedDirectiveDefinitionDataByDirectiveName.set(name, {
448
+ argumentDataByArgumentName,
449
+ executableLocations: new Set(incomingData.executableLocations),
450
+ name,
451
+ repeatable: incomingData.repeatable,
452
+ subgraphNames: new Set(incomingData.subgraphNames),
453
+ description: incomingData.description,
454
+ });
455
+ return;
456
+ }
457
+ // If the executable directive has not been defined in at least one graph, the definition should not be persisted
458
+ if (existingData.subgraphNames.size + 1 !== subgraphNumber) {
459
+ persistedDirectiveDefinitionDataByDirectiveName.delete(name);
460
+ return;
461
+ }
462
+ setMutualExecutableLocations(existingData, incomingData.executableLocations);
463
+ // If there are no mutually defined executable locations, the definition should not be persisted
464
+ if (existingData.executableLocations.size < 1) {
465
+ persistedDirectiveDefinitionDataByDirectiveName.delete(name);
466
+ return;
467
+ }
468
+ for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
469
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
470
+ upsertInputValueData(existingData.argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
471
+ }
472
+ setLongestDescription(existingData, incomingData);
473
+ existingData.repeatable &&= incomingData.repeatable;
474
+ (0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
475
+ }
476
+ exports.upsertPersistedDirectiveDefinitionData = upsertPersistedDirectiveDefinitionData;
477
+ function addScalarDefinitionDataByNode(parentDefinitionDataByTypeName, node, directivesByDirectiveName) {
478
+ const name = node.name.value;
479
+ parentDefinitionDataByTypeName.set(name, {
341
480
  directivesByDirectiveName,
342
481
  kind: node.kind,
343
482
  node: (0, ast_1.getMutableScalarNode)(node),
344
- typeName,
483
+ persistedDirectivesData: newPersistedDirectivesData(),
484
+ name,
345
485
  description: (0, utils_1.formatDescription)(node.description),
346
486
  });
347
487
  }
348
- exports.upsertScalarDefinitionDataByNode = upsertScalarDefinitionDataByNode;
349
- function upsertScalarExtensionDataByNode(parentExtensionDataByTypeName, node, directivesByDirectiveName) {
350
- const typeName = node.name.value;
351
- parentExtensionDataByTypeName.set(typeName, {
488
+ exports.addScalarDefinitionDataByNode = addScalarDefinitionDataByNode;
489
+ function addScalarExtensionDataByNode(parentExtensionDataByTypeName, node, directivesByDirectiveName) {
490
+ const name = node.name.value;
491
+ parentExtensionDataByTypeName.set(name, {
352
492
  directivesByDirectiveName,
353
493
  kind: node.kind,
354
- typeName,
494
+ name,
355
495
  });
356
496
  }
357
- exports.upsertScalarExtensionDataByNode = upsertScalarExtensionDataByNode;
497
+ exports.addScalarExtensionDataByNode = addScalarExtensionDataByNode;
358
498
  function extractUniqueUnionMembers(members, membersByMemberTypeName, errors, unionTypeName, abstractToConcreteTypeNames, referencedTypeNames) {
359
499
  for (const member of members) {
360
500
  const memberTypeName = member.name.value;
@@ -377,38 +517,54 @@ function extractUniqueUnionMembers(members, membersByMemberTypeName, errors, uni
377
517
  return membersByMemberTypeName;
378
518
  }
379
519
  exports.extractUniqueUnionMembers = extractUniqueUnionMembers;
380
- function upsertUnionDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, abstractToConcreteTypeNames, referencedTypeNames) {
381
- const typeName = node.name.value;
520
+ function addUnionDefinitionDataByNode(parentDefinitionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, abstractToConcreteTypeNames, referencedTypeNames) {
521
+ const name = node.name.value;
382
522
  if (!node.types?.length) {
383
- errors.push((0, errors_1.noDefinedUnionMembersError)(typeName));
523
+ errors.push((0, errors_1.noDefinedUnionMembersError)(name));
384
524
  return;
385
525
  }
386
- parentDefinitionDataByTypeName.set(typeName, {
387
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
526
+ parentDefinitionDataByTypeName.set(name, {
527
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
388
528
  kind: node.kind,
389
- memberByMemberTypeName: extractUniqueUnionMembers(node.types, new Map(), errors, typeName, abstractToConcreteTypeNames, referencedTypeNames),
529
+ memberByMemberTypeName: extractUniqueUnionMembers(node.types, new Map(), errors, name, abstractToConcreteTypeNames, referencedTypeNames),
390
530
  node: (0, ast_1.getMutableUnionNode)(node),
391
- typeName,
531
+ persistedDirectivesData: newPersistedDirectivesData(),
532
+ name,
392
533
  description: (0, utils_1.formatDescription)(node.description),
393
534
  });
394
535
  }
395
- exports.upsertUnionDefinitionDataByNode = upsertUnionDefinitionDataByNode;
396
- function upsertUnionExtensionDataByNode(parentExtensionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, abstractToConcreteTypeNames, referencedTypeNames) {
397
- const typeName = node.name.value;
398
- parentExtensionDataByTypeName.set(typeName, {
399
- directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, typeName),
536
+ exports.addUnionDefinitionDataByNode = addUnionDefinitionDataByNode;
537
+ function addUnionExtensionDataByNode(parentExtensionDataByTypeName, node, errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, abstractToConcreteTypeNames, referencedTypeNames) {
538
+ const name = node.name.value;
539
+ parentExtensionDataByTypeName.set(name, {
540
+ directivesByDirectiveName: extractDirectives(node, new Map(), errors, directiveDefinitionByDirectiveName, handledRepeatedDirectivesByHostPath, name),
400
541
  kind: node.kind,
401
542
  memberByMemberTypeName: extractUniqueUnionMembers(
402
543
  // Undefined or empty node.types is handled earlier
403
- node.types, new Map(), errors, typeName, abstractToConcreteTypeNames, referencedTypeNames),
404
- typeName,
544
+ node.types, new Map(), errors, name, abstractToConcreteTypeNames, referencedTypeNames),
545
+ name,
405
546
  });
406
547
  }
407
- exports.upsertUnionExtensionDataByNode = upsertUnionExtensionDataByNode;
548
+ exports.addUnionExtensionDataByNode = addUnionExtensionDataByNode;
408
549
  function isTypeNameRootType(typeName, operationByTypeName) {
409
550
  return string_constants_1.ROOT_TYPES.has(typeName) || operationByTypeName.has(typeName);
410
551
  }
411
552
  exports.isTypeNameRootType = isTypeNameRootType;
553
+ function getRenamedRootTypeName(typeName, operationByTypeName) {
554
+ const operationTypeNode = operationByTypeName.get(typeName);
555
+ if (!operationTypeNode) {
556
+ return typeName;
557
+ }
558
+ switch (operationTypeNode) {
559
+ case graphql_1.OperationTypeNode.MUTATION:
560
+ return string_constants_1.MUTATION;
561
+ case graphql_1.OperationTypeNode.SUBSCRIPTION:
562
+ return string_constants_1.SUBSCRIPTION;
563
+ default:
564
+ return string_constants_1.QUERY;
565
+ }
566
+ }
567
+ exports.getRenamedRootTypeName = getRenamedRootTypeName;
412
568
  function convertKindForExtension(node) {
413
569
  switch (node.kind) {
414
570
  case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
@@ -450,7 +606,7 @@ function addExtensionDirectivesToDefinition(directivesByDirectiveName, parentExt
450
606
  }
451
607
  }
452
608
  function addAuthorizationDirectivesToFieldData(authorizationDataByParentTypeName, fieldData) {
453
- const authorizationData = authorizationDataByParentTypeName.get(fieldData.parentTypeName);
609
+ const authorizationData = authorizationDataByParentTypeName.get(fieldData.originalParentTypeName);
454
610
  if (!authorizationData) {
455
611
  return;
456
612
  }
@@ -537,7 +693,7 @@ function mergeUniqueUnionMembers(unionDefinitionData, errors, unionExtensionData
537
693
  }
538
694
  const definitionMembers = unionDefinitionData.memberByMemberTypeName;
539
695
  const extensionMembers = unionExtensionData.memberByMemberTypeName;
540
- const typeName = unionDefinitionData.typeName;
696
+ const typeName = unionDefinitionData.name;
541
697
  for (const [memberName, namedTypeNode] of extensionMembers) {
542
698
  if (!definitionMembers.has(memberName)) {
543
699
  definitionMembers.set(memberName, namedTypeNode);
@@ -548,21 +704,21 @@ function mergeUniqueUnionMembers(unionDefinitionData, errors, unionExtensionData
548
704
  }
549
705
  function getEnumNodeByData(enumDefinitionData, errors, directiveDefinitionByDirectiveName, authorizationDataByParentTypeName, enumExtensionData) {
550
706
  addExtensionDirectivesToDefinition(enumDefinitionData.directivesByDirectiveName, enumExtensionData);
551
- enumDefinitionData.node.directives = getValidFlattenedDirectiveArray(enumDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, enumDefinitionData.typeName);
707
+ enumDefinitionData.node.directives = getValidFlattenedDirectiveArray(enumDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, enumDefinitionData.name);
552
708
  enumDefinitionData.node.values = childMapToValueArray(enumDefinitionData.enumValueDataByValueName, authorizationDataByParentTypeName);
553
709
  return enumDefinitionData.node;
554
710
  }
555
711
  exports.getEnumNodeByData = getEnumNodeByData;
556
712
  function getInputObjectNodeByData(inputObjectDefinitionData, errors, directiveDefinitionByDirectiveName, authorizationDataByParentTypeName, inputObjectExtensionData) {
557
713
  addExtensionDirectivesToDefinition(inputObjectDefinitionData.directivesByDirectiveName, inputObjectExtensionData);
558
- inputObjectDefinitionData.node.directives = getValidFlattenedDirectiveArray(inputObjectDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, inputObjectDefinitionData.typeName);
714
+ inputObjectDefinitionData.node.directives = getValidFlattenedDirectiveArray(inputObjectDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, inputObjectDefinitionData.name);
559
715
  inputObjectDefinitionData.node.fields = childMapToValueArray(inputObjectDefinitionData.inputValueDataByValueName, authorizationDataByParentTypeName);
560
716
  return inputObjectDefinitionData.node;
561
717
  }
562
718
  exports.getInputObjectNodeByData = getInputObjectNodeByData;
563
719
  function getParentWithFieldsNodeByData(parentWithFieldsData, errors, directiveDefinitionByDirectiveName, authorizationDataByParentTypeName, parentExtensionWithFieldsData) {
564
720
  addExtensionDirectivesToDefinition(parentWithFieldsData.directivesByDirectiveName, parentExtensionWithFieldsData);
565
- parentWithFieldsData.node.directives = getValidFlattenedDirectiveArray(parentWithFieldsData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, parentWithFieldsData.typeName);
721
+ parentWithFieldsData.node.directives = getValidFlattenedDirectiveArray(parentWithFieldsData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, parentWithFieldsData.name);
566
722
  parentWithFieldsData.node.fields = childMapToValueArray(parentWithFieldsData.fieldDataByFieldName, authorizationDataByParentTypeName);
567
723
  parentWithFieldsData.node.interfaces = (0, utils_1.setToNamedTypeNodeArray)(parentWithFieldsData.implementedInterfaceTypeNames);
568
724
  return parentWithFieldsData.node;
@@ -570,7 +726,7 @@ function getParentWithFieldsNodeByData(parentWithFieldsData, errors, directiveDe
570
726
  exports.getParentWithFieldsNodeByData = getParentWithFieldsNodeByData;
571
727
  function getScalarNodeByData(scalarDefinitionData, errors, directiveDefinitionByDirectiveName, scalarExtensionData) {
572
728
  addExtensionDirectivesToDefinition(scalarDefinitionData.directivesByDirectiveName, scalarExtensionData);
573
- scalarDefinitionData.node.directives = getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, scalarDefinitionData.typeName);
729
+ scalarDefinitionData.node.directives = getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, scalarDefinitionData.name);
574
730
  return scalarDefinitionData.node;
575
731
  }
576
732
  exports.getScalarNodeByData = getScalarNodeByData;
@@ -586,7 +742,7 @@ exports.getSchemaNodeByData = getSchemaNodeByData;
586
742
  function getUnionNodeByData(unionDefinitionData, errors, directiveDefinitionByDirectiveName, unionExtensionData) {
587
743
  mergeUniqueUnionMembers(unionDefinitionData, errors, unionExtensionData);
588
744
  addExtensionDirectivesToDefinition(unionDefinitionData.directivesByDirectiveName, unionExtensionData);
589
- unionDefinitionData.node.directives = getValidFlattenedDirectiveArray(unionDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, unionDefinitionData.typeName);
745
+ unionDefinitionData.node.directives = getValidFlattenedDirectiveArray(unionDefinitionData.directivesByDirectiveName, errors, directiveDefinitionByDirectiveName, unionDefinitionData.name);
590
746
  unionDefinitionData.node.types = (0, utils_3.mapToArrayOfValues)(unionDefinitionData.memberByMemberTypeName);
591
747
  return unionDefinitionData.node;
592
748
  }
@@ -597,4 +753,592 @@ function removeInheritableDirectivesFromParentWithFieldsData(parentData) {
597
753
  }
598
754
  }
599
755
  exports.removeInheritableDirectivesFromParentWithFieldsData = removeInheritableDirectivesFromParentWithFieldsData;
756
+ function setLongestDescription(existingData, incomingData) {
757
+ if (!incomingData.description) {
758
+ return;
759
+ }
760
+ if (!existingData.description || existingData.description.value.length < incomingData.description.value.length) {
761
+ existingData.description = { ...incomingData.description, block: true };
762
+ }
763
+ }
764
+ function upsertDeprecatedDirective(persistedDirectivesData, incomingDirectiveNode) {
765
+ if (!incomingDirectiveNode.arguments?.length) {
766
+ return;
767
+ }
768
+ // The argument was already validated in the normalization factory, so it can be safely cast
769
+ const incomingReasonString = incomingDirectiveNode.arguments[0].value.value;
770
+ if (persistedDirectivesData.deprecatedReason.length < incomingReasonString.length) {
771
+ persistedDirectivesData.deprecatedReason = incomingReasonString;
772
+ }
773
+ }
774
+ function upsertTagDirectives(persistedDirectivesData, incomingDirectiveNodes) {
775
+ for (const incomingDirectiveNode of incomingDirectiveNodes) {
776
+ // The argument was already validated in the normalization factory, so it can be safely cast
777
+ const incomingNameString = incomingDirectiveNode.arguments[0].value.value;
778
+ persistedDirectivesData.tags.set(incomingNameString, incomingDirectiveNode);
779
+ }
780
+ }
781
+ function extractPersistedDirectives(persistedDirectivesData, directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName) {
782
+ for (const [directiveName, directiveNodes] of directivesByDirectiveName) {
783
+ if (!persistedDirectiveDefinitionByDirectiveName.has(directiveName)) {
784
+ continue;
785
+ }
786
+ if (directiveName === string_constants_1.DEPRECATED) {
787
+ persistedDirectivesData.isDeprecated = true;
788
+ upsertDeprecatedDirective(persistedDirectivesData, directiveNodes[0]);
789
+ continue;
790
+ }
791
+ if (directiveName === string_constants_1.TAG) {
792
+ upsertTagDirectives(persistedDirectivesData, directiveNodes);
793
+ continue;
794
+ }
795
+ const existingDirectives = persistedDirectivesData.directives.get(directiveName);
796
+ if (!existingDirectives) {
797
+ persistedDirectivesData.directives.set(directiveName, directiveNodes);
798
+ continue;
799
+ }
800
+ existingDirectives.push(...directiveNodes);
801
+ }
802
+ return persistedDirectivesData;
803
+ }
804
+ function upsertEnumValueData(enumValueDataByValueName, incomingData, persistedDirectiveDefinitionByDirectiveName) {
805
+ const existingData = enumValueDataByValueName.get(incomingData.name);
806
+ extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
807
+ if (!existingData) {
808
+ incomingData.node = {
809
+ directives: [],
810
+ kind: incomingData.node.kind,
811
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
812
+ };
813
+ enumValueDataByValueName.set(incomingData.name, incomingData);
814
+ return;
815
+ }
816
+ existingData.appearances += 1;
817
+ setLongestDescription(existingData, incomingData);
818
+ }
819
+ function upsertFieldData(fieldDataByFieldName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors) {
820
+ namedOutputTypeNames.add(incomingData.namedTypeName);
821
+ const existingData = fieldDataByFieldName.get(incomingData.name);
822
+ extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
823
+ if (!existingData) {
824
+ fieldDataByFieldName.set(incomingData.name, incomingData);
825
+ incomingData.node = {
826
+ arguments: [],
827
+ directives: [],
828
+ kind: incomingData.node.kind,
829
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
830
+ type: incomingData.type,
831
+ };
832
+ for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
833
+ inputValueData.node = {
834
+ directives: [],
835
+ kind: inputValueData.node.kind,
836
+ name: (0, utils_1.stringToNameNode)(inputValueData.name),
837
+ type: inputValueData.type,
838
+ };
839
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
840
+ extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
841
+ }
842
+ return;
843
+ }
844
+ const fieldPath = `${existingData.renamedParentTypeName}.${existingData.name}`;
845
+ const { typeErrors, typeNode } = (0, type_merging_1.getLeastRestrictiveMergedTypeNode)(existingData.type, incomingData.type, fieldPath);
846
+ if (typeNode) {
847
+ existingData.type = typeNode;
848
+ }
849
+ else {
850
+ if (!typeErrors || typeErrors.length < 2) {
851
+ throw (0, errors_1.fieldTypeMergeFatalError)(existingData.name);
852
+ }
853
+ errors.push((0, errors_1.incompatibleChildTypesError)(fieldPath, typeErrors[0], typeErrors[1]));
854
+ }
855
+ for (const inputValueData of incomingData.argumentDataByArgumentName.values()) {
856
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
857
+ upsertInputValueData(existingData.argumentDataByArgumentName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
858
+ }
859
+ setLongestDescription(existingData, incomingData);
860
+ existingData.isInaccessible ||= incomingData.isInaccessible;
861
+ (0, utils_3.addMapEntries)(incomingData.isExternalBySubgraphName, existingData.isExternalBySubgraphName);
862
+ (0, utils_3.addMapEntries)(incomingData.isShareableBySubgraphName, existingData.isShareableBySubgraphName);
863
+ (0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
864
+ }
865
+ function upsertInputValueData(inputValueDataByValueName, incomingData, persistedDirectiveDefinitionByDirectiveName, errors) {
866
+ const existingData = inputValueDataByValueName.get(incomingData.name);
867
+ extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
868
+ if (!existingData) {
869
+ incomingData.node = {
870
+ directives: [],
871
+ kind: incomingData.node.kind,
872
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
873
+ type: incomingData.type,
874
+ };
875
+ inputValueDataByValueName.set(incomingData.name, incomingData);
876
+ return;
877
+ }
878
+ setLongestDescription(existingData, incomingData);
879
+ (0, utils_3.addIterableValuesToSet)(incomingData.requiredSubgraphNames, existingData.requiredSubgraphNames);
880
+ (0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
881
+ // TODO refactor type merging
882
+ const { typeErrors, typeNode } = (0, type_merging_1.getMostRestrictiveMergedTypeNode)(existingData.type, incomingData.type, existingData.originalPath);
883
+ if (typeNode) {
884
+ existingData.type = typeNode;
885
+ }
886
+ else {
887
+ if (!typeErrors || typeErrors.length < 2) {
888
+ throw (0, errors_1.fieldTypeMergeFatalError)(existingData.name);
889
+ }
890
+ existingData.isArgument
891
+ ? errors.push((0, errors_1.incompatibleArgumentTypesError)(existingData.name, existingData.renamedPath, typeErrors[0], typeErrors[1]))
892
+ : errors.push((0, errors_1.incompatibleChildTypesError)(existingData.renamedPath, typeErrors[0], typeErrors[1]));
893
+ }
894
+ compareAndValidateInputValueDefaultValues(existingData, incomingData, errors);
895
+ }
896
+ function upsertParentDefinitionData(parentDefinitionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, entityInterfaceFederationDataByTypeName, namedOutputTypeNames, namedInputValueTypeNames, subgraphName, errors) {
897
+ const entityInterfaceData = entityInterfaceFederationDataByTypeName.get(incomingData.name);
898
+ const existingData = parentDefinitionDataByTypeName.get(incomingData.name);
899
+ extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
900
+ if (!existingData) {
901
+ if (entityInterfaceData && entityInterfaceData.interfaceObjectSubgraphs.has(subgraphName)) {
902
+ incomingData.kind = graphql_1.Kind.INTERFACE_TYPE_DEFINITION;
903
+ }
904
+ incomingData.node = {
905
+ kind: incomingData.kind,
906
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
907
+ };
908
+ parentDefinitionDataByTypeName.set(incomingData.name, incomingData);
909
+ switch (incomingData.kind) {
910
+ case graphql_1.Kind.ENUM_TYPE_DEFINITION:
911
+ for (const enumValueData of incomingData.enumValueDataByValueName.values()) {
912
+ enumValueData.node = {
913
+ directives: [],
914
+ kind: enumValueData.node.kind,
915
+ name: (0, utils_1.stringToNameNode)(enumValueData.name),
916
+ };
917
+ extractPersistedDirectives(enumValueData.persistedDirectivesData, enumValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
918
+ }
919
+ return;
920
+ case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
921
+ for (const inputValueData of incomingData.inputValueDataByValueName.values()) {
922
+ inputValueData.node = {
923
+ directives: [],
924
+ kind: inputValueData.node.kind,
925
+ name: (0, utils_1.stringToNameNode)(inputValueData.name),
926
+ type: inputValueData.type,
927
+ };
928
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
929
+ extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
930
+ }
931
+ return;
932
+ case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
933
+ // intentional fallthrough
934
+ case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
935
+ for (const fieldData of incomingData.fieldDataByFieldName.values()) {
936
+ fieldData.node = {
937
+ arguments: [],
938
+ directives: [],
939
+ kind: fieldData.node.kind,
940
+ name: (0, utils_1.stringToNameNode)(fieldData.name),
941
+ type: fieldData.type,
942
+ };
943
+ namedOutputTypeNames.add(fieldData.namedTypeName);
944
+ extractPersistedDirectives(fieldData.persistedDirectivesData, fieldData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
945
+ for (const inputValueData of fieldData.argumentDataByArgumentName.values()) {
946
+ inputValueData.node = {
947
+ directives: [],
948
+ kind: inputValueData.node.kind,
949
+ name: (0, utils_1.stringToNameNode)(inputValueData.name),
950
+ type: inputValueData.type,
951
+ };
952
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
953
+ extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
954
+ }
955
+ }
956
+ return;
957
+ default:
958
+ // Scalar and Union
959
+ return;
960
+ }
961
+ }
962
+ setLongestDescription(existingData, incomingData);
963
+ if (existingData.kind !== incomingData.kind) {
964
+ if (!entityInterfaceData ||
965
+ !entityInterfaceData.interfaceObjectSubgraphs.has(subgraphName) ||
966
+ existingData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION ||
967
+ incomingData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
968
+ throw (0, errors_1.incompatibleParentKindFatalError)(existingData.name, existingData.kind, incomingData.kind);
969
+ }
970
+ }
971
+ switch (existingData.kind) {
972
+ case graphql_1.Kind.ENUM_TYPE_DEFINITION:
973
+ existingData.appearances += 1;
974
+ for (const data of incomingData.enumValueDataByValueName.values()) {
975
+ upsertEnumValueData(existingData.enumValueDataByValueName, data, persistedDirectiveDefinitionByDirectiveName);
976
+ }
977
+ return;
978
+ case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
979
+ (0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
980
+ for (const inputValueData of incomingData.inputValueDataByValueName.values()) {
981
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
982
+ upsertInputValueData(existingData.inputValueDataByValueName, inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
983
+ }
984
+ return;
985
+ case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
986
+ // intentional fallthrough
987
+ case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
988
+ const objectData = incomingData;
989
+ (0, utils_3.addIterableValuesToSet)(objectData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
990
+ (0, utils_3.addIterableValuesToSet)(objectData.subgraphNames, existingData.subgraphNames);
991
+ for (const fieldData of objectData.fieldDataByFieldName.values()) {
992
+ upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
993
+ }
994
+ return;
995
+ case graphql_1.Kind.UNION_TYPE_DEFINITION:
996
+ (0, utils_3.addMapEntries)(incomingData.memberByMemberTypeName, existingData.memberByMemberTypeName);
997
+ return;
998
+ default:
999
+ // Scalar type
1000
+ return;
1001
+ }
1002
+ }
1003
+ exports.upsertParentDefinitionData = upsertParentDefinitionData;
1004
+ function upsertObjectExtensionData(parentExtensionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors) {
1005
+ const existingData = parentExtensionDataByTypeName.get(incomingData.name);
1006
+ extractPersistedDirectives(existingData?.persistedDirectivesData || incomingData.persistedDirectivesData, incomingData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
1007
+ if (!existingData) {
1008
+ incomingData.node = {
1009
+ kind: incomingData.kind,
1010
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
1011
+ };
1012
+ for (const fieldData of incomingData.fieldDataByFieldName.values()) {
1013
+ fieldData.node = {
1014
+ arguments: [],
1015
+ directives: [],
1016
+ kind: fieldData.node.kind,
1017
+ name: (0, utils_1.stringToNameNode)(fieldData.name),
1018
+ type: fieldData.type,
1019
+ };
1020
+ namedOutputTypeNames.add(fieldData.namedTypeName);
1021
+ extractPersistedDirectives(fieldData.persistedDirectivesData, fieldData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
1022
+ for (const inputValueData of fieldData.argumentDataByArgumentName.values()) {
1023
+ inputValueData.node = {
1024
+ directives: [],
1025
+ kind: inputValueData.node.kind,
1026
+ name: (0, utils_1.stringToNameNode)(inputValueData.name),
1027
+ type: inputValueData.type,
1028
+ };
1029
+ namedInputValueTypeNames.add((0, ast_1.getTypeNodeNamedTypeName)(inputValueData.type));
1030
+ extractPersistedDirectives(inputValueData.persistedDirectivesData, inputValueData.directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName);
1031
+ }
1032
+ }
1033
+ parentExtensionDataByTypeName.set(incomingData.name, incomingData);
1034
+ return;
1035
+ }
1036
+ (0, utils_3.addIterableValuesToSet)(incomingData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
1037
+ (0, utils_3.addIterableValuesToSet)(incomingData.subgraphNames, existingData.subgraphNames);
1038
+ for (const fieldData of incomingData.fieldDataByFieldName.values()) {
1039
+ upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
1040
+ }
1041
+ }
1042
+ exports.upsertObjectExtensionData = upsertObjectExtensionData;
1043
+ function upsertPersistedDirectivesData(existingData, incomingData) {
1044
+ if (incomingData.isDeprecated && existingData.deprecatedReason.length < incomingData.deprecatedReason.length) {
1045
+ existingData.isDeprecated = true;
1046
+ existingData.deprecatedReason = incomingData.deprecatedReason;
1047
+ }
1048
+ for (const [directiveName, directiveNodes] of incomingData.directives) {
1049
+ const existingDirectiveNodes = existingData.directives.get(directiveName);
1050
+ if (!existingDirectiveNodes) {
1051
+ existingData.directives.set(directiveName, directiveNodes);
1052
+ continue;
1053
+ }
1054
+ existingDirectiveNodes.push(...directiveNodes);
1055
+ }
1056
+ for (const [tagName, tagDirectiveNode] of incomingData.tags) {
1057
+ if (existingData.tags.has(tagName)) {
1058
+ continue;
1059
+ }
1060
+ existingData.tags.set(tagName, tagDirectiveNode);
1061
+ }
1062
+ }
1063
+ function pushAuthorizationDirectives(fieldData, authorizationData) {
1064
+ if (!authorizationData) {
1065
+ return;
1066
+ }
1067
+ const fieldAuthorizationData = authorizationData.fieldAuthorizationDataByFieldName.get(fieldData.name);
1068
+ if (!fieldAuthorizationData) {
1069
+ return;
1070
+ }
1071
+ if (fieldAuthorizationData.requiresAuthentication) {
1072
+ fieldData.persistedDirectivesData.directives.set(string_constants_1.AUTHENTICATED, [(0, utils_3.generateSimpleDirective)(string_constants_1.AUTHENTICATED)]);
1073
+ }
1074
+ if (fieldAuthorizationData.requiredScopes.length > 0) {
1075
+ fieldData.persistedDirectivesData.directives.set(string_constants_1.REQUIRES_SCOPES, [
1076
+ (0, utils_3.generateRequiresScopesDirective)(fieldAuthorizationData.requiredScopes),
1077
+ ]);
1078
+ }
1079
+ }
1080
+ exports.pushAuthorizationDirectives = pushAuthorizationDirectives;
1081
+ function upsertValidObjectExtensionData(parentDefinitionDataByTypeName, incomingData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors, authorizationData) {
1082
+ const existingData = parentDefinitionDataByTypeName.get(incomingData.name);
1083
+ if (!existingData) {
1084
+ if (incomingData.isRootType) {
1085
+ for (const fieldData of incomingData.fieldDataByFieldName.values()) {
1086
+ pushAuthorizationDirectives(fieldData, authorizationData);
1087
+ }
1088
+ parentDefinitionDataByTypeName.set(incomingData.name, {
1089
+ directivesByDirectiveName: incomingData.directivesByDirectiveName,
1090
+ fieldDataByFieldName: incomingData.fieldDataByFieldName,
1091
+ implementedInterfaceTypeNames: incomingData.implementedInterfaceTypeNames,
1092
+ isRootType: true,
1093
+ isEntity: false,
1094
+ kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
1095
+ name: incomingData.name,
1096
+ node: {
1097
+ kind: graphql_1.Kind.OBJECT_TYPE_DEFINITION,
1098
+ name: (0, utils_1.stringToNameNode)(incomingData.name),
1099
+ },
1100
+ persistedDirectivesData: incomingData.persistedDirectivesData,
1101
+ renamedTypeName: incomingData.renamedTypeName,
1102
+ subgraphNames: incomingData.subgraphNames,
1103
+ });
1104
+ return;
1105
+ }
1106
+ errors.push((0, errors_1.noBaseTypeExtensionError)(incomingData.name));
1107
+ return;
1108
+ }
1109
+ if (existingData.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
1110
+ throw (0, errors_1.incompatibleParentKindFatalError)(existingData.name, graphql_1.Kind.OBJECT_TYPE_DEFINITION, existingData.kind);
1111
+ }
1112
+ upsertPersistedDirectivesData(existingData.persistedDirectivesData, incomingData.persistedDirectivesData);
1113
+ (0, utils_3.addIterableValuesToSet)(incomingData.implementedInterfaceTypeNames, existingData.implementedInterfaceTypeNames);
1114
+ for (const fieldData of incomingData.fieldDataByFieldName.values()) {
1115
+ upsertFieldData(existingData.fieldDataByFieldName, fieldData, persistedDirectiveDefinitionByDirectiveName, namedOutputTypeNames, namedInputValueTypeNames, errors);
1116
+ }
1117
+ }
1118
+ exports.upsertValidObjectExtensionData = upsertValidObjectExtensionData;
1119
+ function generateDeprecatedDirective(reason) {
1120
+ return {
1121
+ kind: graphql_1.Kind.DIRECTIVE,
1122
+ name: (0, utils_1.stringToNameNode)(string_constants_1.DEPRECATED),
1123
+ arguments: [
1124
+ {
1125
+ kind: graphql_1.Kind.ARGUMENT,
1126
+ name: (0, utils_1.stringToNameNode)(string_constants_1.REASON),
1127
+ value: {
1128
+ kind: graphql_1.Kind.STRING,
1129
+ value: reason || string_constants_1.DEPRECATED_DEFAULT_ARGUMENT_VALUE, // use the default value if reason is empty
1130
+ },
1131
+ },
1132
+ ],
1133
+ };
1134
+ }
1135
+ function getValidFlattenedPersistedDirectiveNodeArray(directivesByDirectiveName, persistedDirectiveDefinitionByDirectiveName, hostPath, errors) {
1136
+ const persistedDirectiveNodes = [];
1137
+ for (const [directiveName, directiveNodes] of directivesByDirectiveName) {
1138
+ const persistedDirectiveDefinition = persistedDirectiveDefinitionByDirectiveName.get(directiveName);
1139
+ if (!persistedDirectiveDefinition) {
1140
+ continue;
1141
+ }
1142
+ if (directiveNodes.length < 2) {
1143
+ persistedDirectiveNodes.push(...directiveNodes);
1144
+ continue;
1145
+ }
1146
+ if (!persistedDirectiveDefinition.repeatable) {
1147
+ errors.push((0, errors_1.invalidRepeatedFederatedDirectiveErrorMessage)(directiveName, hostPath));
1148
+ continue;
1149
+ }
1150
+ persistedDirectiveNodes.push(...directiveNodes);
1151
+ }
1152
+ return persistedDirectiveNodes;
1153
+ }
1154
+ function getPersistedDirectiveNodes(nodeData, persistedDirectiveDefinitionByDirectiveName, errors) {
1155
+ const persistedDirectiveNodes = [...nodeData.persistedDirectivesData.tags.values()];
1156
+ if (nodeData.persistedDirectivesData.isDeprecated) {
1157
+ persistedDirectiveNodes.push(generateDeprecatedDirective(nodeData.persistedDirectivesData.deprecatedReason));
1158
+ }
1159
+ persistedDirectiveNodes.push(...getValidFlattenedPersistedDirectiveNodeArray(nodeData.persistedDirectivesData.directives, persistedDirectiveDefinitionByDirectiveName, nodeData.name, errors));
1160
+ return persistedDirectiveNodes;
1161
+ }
1162
+ function getNodeWithPersistedDirectivesByData(data, persistedDirectiveDefinitionByDirectiveName, errors) {
1163
+ data.node.name = (0, utils_1.stringToNameNode)(data.name);
1164
+ data.node.description = data.description;
1165
+ data.node.directives = getPersistedDirectiveNodes(data, persistedDirectiveDefinitionByDirectiveName, errors);
1166
+ return data.node;
1167
+ }
1168
+ exports.getNodeWithPersistedDirectivesByData = getNodeWithPersistedDirectivesByData;
1169
+ function getNodeWithPersistedDirectivesByFieldData(fieldData, persistedDirectiveDefinitionByDirectiveName, argumentNodes, errors) {
1170
+ fieldData.node.arguments = argumentNodes;
1171
+ fieldData.node.name = (0, utils_1.stringToNameNode)(fieldData.name);
1172
+ fieldData.node.type = fieldData.type;
1173
+ fieldData.node.description = fieldData.description;
1174
+ fieldData.node.directives = getPersistedDirectiveNodes(fieldData, persistedDirectiveDefinitionByDirectiveName, errors);
1175
+ return fieldData.node;
1176
+ }
1177
+ exports.getNodeWithPersistedDirectivesByFieldData = getNodeWithPersistedDirectivesByFieldData;
1178
+ function getNodeWithPersistedDirectivesByInputValueData(inputValueData, persistedDirectiveDefinitionByDirectiveName, errors) {
1179
+ inputValueData.node.name = (0, utils_1.stringToNameNode)(inputValueData.name);
1180
+ inputValueData.node.type = inputValueData.type;
1181
+ inputValueData.node.description = inputValueData.description;
1182
+ inputValueData.node.directives = getPersistedDirectiveNodes(inputValueData, persistedDirectiveDefinitionByDirectiveName, errors);
1183
+ if (inputValueData.includeDefaultValue) {
1184
+ inputValueData.node.defaultValue = inputValueData.defaultValue;
1185
+ }
1186
+ return inputValueData.node;
1187
+ }
1188
+ exports.getNodeWithPersistedDirectivesByInputValueData = getNodeWithPersistedDirectivesByInputValueData;
1189
+ function getValidFieldArgumentNodes(fieldData, persistedDirectiveDefinitionByDirectiveName, fieldConfigurationByFieldPath, errors) {
1190
+ const argumentNodes = [];
1191
+ const argumentNames = [];
1192
+ const invalidRequiredArguments = [];
1193
+ const fieldPath = `${fieldData.renamedParentTypeName}.${fieldData.name}`;
1194
+ for (const [argumentName, inputValueData] of fieldData.argumentDataByArgumentName) {
1195
+ if (fieldData.subgraphNames.size === inputValueData.subgraphNames.size) {
1196
+ argumentNames.push(argumentName);
1197
+ argumentNodes.push(getNodeWithPersistedDirectivesByInputValueData(inputValueData, persistedDirectiveDefinitionByDirectiveName, errors));
1198
+ }
1199
+ else if (isTypeRequired(inputValueData.type)) {
1200
+ invalidRequiredArguments.push({
1201
+ inputValueName: argumentName,
1202
+ missingSubgraphs: (0, utils_3.getEntriesNotInHashSet)(fieldData.subgraphNames, inputValueData.subgraphNames),
1203
+ requiredSubgraphs: [...inputValueData.requiredSubgraphNames],
1204
+ });
1205
+ }
1206
+ }
1207
+ if (invalidRequiredArguments.length > 0) {
1208
+ errors.push((0, errors_1.invalidRequiredInputValueError)(string_constants_1.FIELD, fieldPath, invalidRequiredArguments));
1209
+ }
1210
+ else if (argumentNames.length > 0) {
1211
+ fieldConfigurationByFieldPath.set(fieldPath, {
1212
+ argumentNames,
1213
+ fieldName: fieldData.name,
1214
+ typeName: fieldData.renamedParentTypeName,
1215
+ });
1216
+ }
1217
+ return argumentNodes;
1218
+ }
1219
+ exports.getValidFieldArgumentNodes = getValidFieldArgumentNodes;
1220
+ function addValidatedArgumentNodes(argumentNodes, hostData, persistedDirectiveDefinitionByDirectiveName, errors, argumentNamesForFieldConfiguration) {
1221
+ const invalidRequiredArgumentErrors = [];
1222
+ for (const [argumentName, argumentData] of hostData.argumentDataByArgumentName) {
1223
+ const missingSubgraphs = (0, utils_3.getEntriesNotInHashSet)(hostData.subgraphNames, argumentData.subgraphNames);
1224
+ if (missingSubgraphs.length > 0) {
1225
+ // Required arguments must be defined in all subgraphs that define the field
1226
+ if (argumentData.requiredSubgraphNames.size > 0) {
1227
+ invalidRequiredArgumentErrors.push({
1228
+ inputValueName: argumentName,
1229
+ missingSubgraphs,
1230
+ requiredSubgraphs: [...argumentData.requiredSubgraphNames],
1231
+ });
1232
+ }
1233
+ /* If the argument is always optional, but it's not defined in all subgraphs that define the field,
1234
+ the argument should not be included in the federated graph */
1235
+ continue;
1236
+ }
1237
+ argumentNodes.push(getNodeWithPersistedDirectivesByInputValueData(argumentData, persistedDirectiveDefinitionByDirectiveName, errors));
1238
+ if (argumentNamesForFieldConfiguration) {
1239
+ argumentNamesForFieldConfiguration.add(argumentName);
1240
+ }
1241
+ }
1242
+ if (invalidRequiredArgumentErrors.length > 0) {
1243
+ errors.push((0, errors_1.invalidRequiredInputValueError)(string_constants_1.DIRECTIVE_DEFINITION, `@${hostData.name}`, invalidRequiredArgumentErrors));
1244
+ return false;
1245
+ }
1246
+ return true;
1247
+ }
1248
+ function addValidPersistedDirectiveDefinitionNodeByData(definitions, data, persistedDirectiveDefinitionByDirectiveName, errors) {
1249
+ const argumentNodes = [];
1250
+ if (!addValidatedArgumentNodes(argumentNodes, data, persistedDirectiveDefinitionByDirectiveName, errors)) {
1251
+ return;
1252
+ }
1253
+ definitions.push({
1254
+ arguments: argumentNodes,
1255
+ kind: graphql_1.Kind.DIRECTIVE_DEFINITION,
1256
+ locations: (0, utils_1.setToNameNodeArray)(data.executableLocations),
1257
+ name: (0, utils_1.stringToNameNode)(data.name),
1258
+ repeatable: data.repeatable,
1259
+ description: data.description,
1260
+ });
1261
+ }
1262
+ exports.addValidPersistedDirectiveDefinitionNodeByData = addValidPersistedDirectiveDefinitionNodeByData;
1263
+ function isShareabilityOfAllFieldInstancesValid(fieldData) {
1264
+ let shareableFields = 0;
1265
+ let unshareableFields = 0;
1266
+ for (const [subgraphName, isShareable] of fieldData.isShareableBySubgraphName) {
1267
+ /*
1268
+ shareability is ignored if:
1269
+ 1. the field is external
1270
+ 2. the field is overridden by another subgraph (in which case it has not been upserted)
1271
+ */
1272
+ if (fieldData.isExternalBySubgraphName.get(subgraphName)) {
1273
+ continue;
1274
+ }
1275
+ if (isShareable) {
1276
+ if (unshareableFields) {
1277
+ return false;
1278
+ }
1279
+ shareableFields += 1;
1280
+ continue;
1281
+ }
1282
+ unshareableFields += 1;
1283
+ if (shareableFields || unshareableFields > 1) {
1284
+ return false;
1285
+ }
1286
+ }
1287
+ return true;
1288
+ }
1289
+ exports.isShareabilityOfAllFieldInstancesValid = isShareabilityOfAllFieldInstancesValid;
1290
+ function isFieldExternalInAllMutualSubgraphs(subgraphs, fieldData) {
1291
+ const mutualSubgraphs = (0, utils_3.getAllMutualEntries)(subgraphs, fieldData.subgraphNames);
1292
+ if (mutualSubgraphs.size < 1) {
1293
+ return false;
1294
+ }
1295
+ for (const mutualSubgraph of mutualSubgraphs) {
1296
+ const isExternal = fieldData.isExternalBySubgraphName.get(mutualSubgraph);
1297
+ if (isExternal) {
1298
+ continue;
1299
+ }
1300
+ return false;
1301
+ }
1302
+ return true;
1303
+ }
1304
+ exports.isFieldExternalInAllMutualSubgraphs = isFieldExternalInAllMutualSubgraphs;
1305
+ var MergeMethod;
1306
+ (function (MergeMethod) {
1307
+ MergeMethod[MergeMethod["UNION"] = 0] = "UNION";
1308
+ MergeMethod[MergeMethod["INTERSECTION"] = 1] = "INTERSECTION";
1309
+ MergeMethod[MergeMethod["CONSISTENT"] = 2] = "CONSISTENT";
1310
+ })(MergeMethod || (exports.MergeMethod = MergeMethod = {}));
1311
+ function isTypeValidImplementation(originalType, implementationType, concreteTypeNamesByAbstractTypeName) {
1312
+ if (originalType.kind === graphql_1.Kind.NON_NULL_TYPE) {
1313
+ if (implementationType.kind !== graphql_1.Kind.NON_NULL_TYPE) {
1314
+ return false;
1315
+ }
1316
+ return isTypeValidImplementation(originalType.type, implementationType.type, concreteTypeNamesByAbstractTypeName);
1317
+ }
1318
+ if (implementationType.kind === graphql_1.Kind.NON_NULL_TYPE) {
1319
+ return isTypeValidImplementation(originalType, implementationType.type, concreteTypeNamesByAbstractTypeName);
1320
+ }
1321
+ switch (originalType.kind) {
1322
+ case graphql_1.Kind.NAMED_TYPE:
1323
+ if (implementationType.kind === graphql_1.Kind.NAMED_TYPE) {
1324
+ const originalTypeName = originalType.name.value;
1325
+ const implementationTypeName = implementationType.name.value;
1326
+ if (originalTypeName === implementationTypeName) {
1327
+ return true;
1328
+ }
1329
+ const concreteTypes = concreteTypeNamesByAbstractTypeName.get(originalTypeName);
1330
+ if (!concreteTypes) {
1331
+ return false;
1332
+ }
1333
+ return concreteTypes.has(implementationTypeName);
1334
+ }
1335
+ return false;
1336
+ default:
1337
+ if (implementationType.kind === graphql_1.Kind.LIST_TYPE) {
1338
+ return isTypeValidImplementation(originalType.type, implementationType.type, concreteTypeNamesByAbstractTypeName);
1339
+ }
1340
+ return false;
1341
+ }
1342
+ }
1343
+ exports.isTypeValidImplementation = isTypeValidImplementation;
600
1344
  //# sourceMappingURL=utils.js.map