@wundergraph/composition 0.35.0 → 0.36.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.
- package/dist/ast/utils.js.map +1 -1
- package/dist/errors/errors.d.ts +16 -16
- package/dist/errors/errors.js +81 -82
- package/dist/errors/errors.js.map +1 -1
- package/dist/federation/federation-factory.d.ts +11 -3
- package/dist/federation/federation-factory.js +137 -10
- package/dist/federation/federation-factory.js.map +1 -1
- package/dist/federation/utils.d.ts +2 -1
- package/dist/federation/utils.js +11 -0
- package/dist/federation/utils.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/dist/normalization/directive-definition-data.d.ts +25 -0
- package/dist/normalization/directive-definition-data.js +559 -0
- package/dist/normalization/directive-definition-data.js.map +1 -0
- package/dist/normalization/normalization-factory.d.ts +36 -11
- package/dist/normalization/normalization-factory.js +678 -124
- package/dist/normalization/normalization-factory.js.map +1 -1
- package/dist/normalization/utils.d.ts +27 -4
- package/dist/normalization/utils.js +31 -114
- package/dist/normalization/utils.js.map +1 -1
- package/dist/normalization/walkers.js +71 -68
- package/dist/normalization/walkers.js.map +1 -1
- package/dist/schema-building/ast.d.ts +1 -0
- package/dist/schema-building/ast.js +9 -0
- package/dist/schema-building/ast.js.map +1 -1
- package/dist/schema-building/type-definition-data.d.ts +36 -2
- package/dist/schema-building/type-definition-data.js.map +1 -1
- package/dist/schema-building/utils.d.ts +10 -20
- package/dist/schema-building/utils.js +54 -333
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/composition-version.js +1 -1
- package/dist/utils/constants.d.ts +25 -3
- package/dist/utils/constants.js +200 -134
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/string-constants.d.ts +14 -0
- package/dist/utils/string-constants.js +30 -3
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/utils/utils.d.ts +2 -1
- package/dist/utils/utils.js +7 -2
- package/dist/utils/utils.js.map +1 -1
- package/package.json +3 -2
|
@@ -41,7 +41,9 @@ class NormalizationFactory {
|
|
|
41
41
|
conditionalFieldDataByCoordinates = new Map();
|
|
42
42
|
configurationDataByParentTypeName = new Map();
|
|
43
43
|
customDirectiveDefinitions = new Map();
|
|
44
|
+
definedDirectiveNames = new Set();
|
|
44
45
|
directiveDefinitionByDirectiveName = new Map();
|
|
46
|
+
directiveDefinitionDataByDirectiveName = (0, utils_2.initializeDirectiveDefinitionDatas)();
|
|
45
47
|
edfsDirectiveReferences = new Set();
|
|
46
48
|
errors = [];
|
|
47
49
|
entityDataByTypeName = new Map();
|
|
@@ -50,12 +52,15 @@ class NormalizationFactory {
|
|
|
50
52
|
unvalidatedExternalFieldCoords = new Set();
|
|
51
53
|
interfaceTypeNamesWithAuthorizationDirectives = new Set();
|
|
52
54
|
internalGraph;
|
|
55
|
+
invalidConfigureDescriptionNodeDatas = [];
|
|
56
|
+
invalidRepeatedDirectiveNameByCoords = new Map();
|
|
53
57
|
isCurrentParentExtension = false;
|
|
58
|
+
isParentObjectExternal = false;
|
|
59
|
+
isParentObjectShareable = false;
|
|
54
60
|
isSubgraphEventDrivenGraph = false;
|
|
55
61
|
isSubgraphVersionTwo = false;
|
|
56
62
|
fieldSetDataByTypeName = new Map();
|
|
57
63
|
heirFieldAuthorizationDataByTypeName = new Map();
|
|
58
|
-
handledRepeatedDirectivesByHostPath = new Map();
|
|
59
64
|
lastParentNodeKind = graphql_1.Kind.NULL;
|
|
60
65
|
lastChildNodeKind = graphql_1.Kind.NULL;
|
|
61
66
|
leafTypeNamesWithAuthorizationDirectives = new Set();
|
|
@@ -68,7 +73,7 @@ class NormalizationFactory {
|
|
|
68
73
|
parentsWithChildArguments = new Set();
|
|
69
74
|
overridesByTargetSubgraphName = new Map();
|
|
70
75
|
invalidOrScopesHostPaths = new Set();
|
|
71
|
-
|
|
76
|
+
schemaData;
|
|
72
77
|
referencedDirectiveNames = new Set();
|
|
73
78
|
referencedTypeNames = new Set();
|
|
74
79
|
renamedParentTypeName = '';
|
|
@@ -82,10 +87,10 @@ class NormalizationFactory {
|
|
|
82
87
|
this.subgraphName = subgraphName || string_constants_1.NOT_APPLICABLE;
|
|
83
88
|
this.internalGraph = internalGraph;
|
|
84
89
|
this.internalGraph.setSubgraphName(this.subgraphName);
|
|
85
|
-
this.
|
|
90
|
+
this.schemaData = {
|
|
86
91
|
directivesByDirectiveName: new Map(),
|
|
87
92
|
kind: graphql_1.Kind.SCHEMA_DEFINITION,
|
|
88
|
-
|
|
93
|
+
name: string_constants_1.SCHEMA,
|
|
89
94
|
operationTypes: new Map(),
|
|
90
95
|
};
|
|
91
96
|
}
|
|
@@ -201,104 +206,271 @@ class NormalizationFactory {
|
|
|
201
206
|
}
|
|
202
207
|
return authorizationData;
|
|
203
208
|
}
|
|
204
|
-
|
|
209
|
+
isTypeNameRootType(typeName) {
|
|
210
|
+
return string_constants_1.ROOT_TYPE_NAMES.has(typeName) || this.operationTypeNodeByTypeName.has(typeName);
|
|
211
|
+
}
|
|
212
|
+
isArgumentValueValid(typeNode, argumentValue) {
|
|
213
|
+
if (argumentValue.kind === graphql_1.Kind.NULL) {
|
|
214
|
+
return typeNode.kind !== graphql_1.Kind.NON_NULL_TYPE;
|
|
215
|
+
}
|
|
216
|
+
switch (typeNode.kind) {
|
|
217
|
+
case graphql_1.Kind.LIST_TYPE: {
|
|
218
|
+
if (argumentValue.kind !== graphql_1.Kind.LIST) {
|
|
219
|
+
// This handles List coercion
|
|
220
|
+
return this.isArgumentValueValid((0, ast_1.getNamedTypeNode)(typeNode.type), argumentValue);
|
|
221
|
+
}
|
|
222
|
+
for (const value of argumentValue.values) {
|
|
223
|
+
if (!this.isArgumentValueValid(typeNode.type, value)) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return true;
|
|
228
|
+
}
|
|
229
|
+
case graphql_1.Kind.NAMED_TYPE: {
|
|
230
|
+
switch (typeNode.name.value) {
|
|
231
|
+
case string_constants_1.BOOLEAN_SCALAR: {
|
|
232
|
+
return argumentValue.kind === graphql_1.Kind.BOOLEAN;
|
|
233
|
+
}
|
|
234
|
+
case string_constants_1.FLOAT_SCALAR: {
|
|
235
|
+
return argumentValue.kind === graphql_1.Kind.FLOAT || argumentValue.kind === graphql_1.Kind.INT;
|
|
236
|
+
}
|
|
237
|
+
case string_constants_1.ID_SCALAR: {
|
|
238
|
+
return argumentValue.kind === graphql_1.Kind.STRING || argumentValue.kind === graphql_1.Kind.INT;
|
|
239
|
+
}
|
|
240
|
+
case string_constants_1.INT_SCALAR: {
|
|
241
|
+
return argumentValue.kind === graphql_1.Kind.INT;
|
|
242
|
+
}
|
|
243
|
+
case string_constants_1.FIELD_SET_SCALAR:
|
|
244
|
+
// intentional fallthrough
|
|
245
|
+
case string_constants_1.SCOPE_SCALAR:
|
|
246
|
+
// intentional fallthrough
|
|
247
|
+
case string_constants_1.STRING_SCALAR: {
|
|
248
|
+
return argumentValue.kind === graphql_1.Kind.STRING;
|
|
249
|
+
}
|
|
250
|
+
case string_constants_1.LINK_IMPORT: {
|
|
251
|
+
return true;
|
|
252
|
+
}
|
|
253
|
+
case string_constants_1.LINK_PURPOSE: {
|
|
254
|
+
if (argumentValue.kind !== graphql_1.Kind.ENUM) {
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
return argumentValue.value === string_constants_1.SECURITY || argumentValue.value === string_constants_1.EXECUTION;
|
|
258
|
+
}
|
|
259
|
+
case string_constants_1.SUBSCRIPTION_FIELD_CONDITION:
|
|
260
|
+
// intentional fallthrough
|
|
261
|
+
case string_constants_1.SUBSCRIPTION_FILTER_CONDITION:
|
|
262
|
+
return argumentValue.kind === graphql_1.Kind.OBJECT;
|
|
263
|
+
default: {
|
|
264
|
+
const parentData = this.parentDefinitionDataByTypeName.get(typeNode.name.value);
|
|
265
|
+
if (!parentData) {
|
|
266
|
+
return false;
|
|
267
|
+
}
|
|
268
|
+
if (parentData.kind === graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
269
|
+
// For now, allow custom scalars to be any value kind.
|
|
270
|
+
return true;
|
|
271
|
+
}
|
|
272
|
+
if (parentData.kind === graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
273
|
+
if (argumentValue.kind !== graphql_1.Kind.ENUM) {
|
|
274
|
+
return false;
|
|
275
|
+
}
|
|
276
|
+
const enumValue = parentData.enumValueDataByValueName.get(argumentValue.value);
|
|
277
|
+
if (!enumValue) {
|
|
278
|
+
return false;
|
|
279
|
+
}
|
|
280
|
+
return !enumValue.directivesByDirectiveName.has(string_constants_1.INACCESSIBLE);
|
|
281
|
+
}
|
|
282
|
+
if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
283
|
+
return false;
|
|
284
|
+
}
|
|
285
|
+
// TODO deep comparison
|
|
286
|
+
return argumentValue.kind === graphql_1.Kind.OBJECT;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
default: {
|
|
291
|
+
return this.isArgumentValueValid(typeNode.type, argumentValue);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
addInheritedDirectivesToFieldData(fieldDirectivesByDirectiveName) {
|
|
296
|
+
if (this.isParentObjectShareable) {
|
|
297
|
+
(0, utils_3.getValueOrDefault)(fieldDirectivesByDirectiveName, string_constants_1.SHAREABLE, () => [(0, utils_3.generateSimpleDirective)(string_constants_1.SHAREABLE)]);
|
|
298
|
+
}
|
|
299
|
+
if (this.isParentObjectExternal) {
|
|
300
|
+
(0, utils_3.getValueOrDefault)(fieldDirectivesByDirectiveName, string_constants_1.EXTERNAL, () => [(0, utils_3.generateSimpleDirective)(string_constants_1.EXTERNAL)]);
|
|
301
|
+
}
|
|
302
|
+
return fieldDirectivesByDirectiveName;
|
|
303
|
+
}
|
|
304
|
+
extractDirectives(node, directivesByDirectiveName) {
|
|
205
305
|
if (!node.directives) {
|
|
206
306
|
return directivesByDirectiveName;
|
|
207
307
|
}
|
|
208
|
-
const hostPath = this.childName ? `${this.originalParentTypeName}.${this.childName}` : this.originalParentTypeName;
|
|
209
|
-
const authorizationDirectives = [];
|
|
210
308
|
for (const directiveNode of node.directives) {
|
|
211
|
-
const errorMessages = (0, utils_4.getDirectiveValidationErrors)(directiveNode, node.kind, directivesByDirectiveName, this.directiveDefinitionByDirectiveName, this.handledRepeatedDirectivesByHostPath, hostPath);
|
|
212
309
|
const directiveName = directiveNode.name.value;
|
|
213
|
-
|
|
214
|
-
|
|
310
|
+
// Don't create pointless repetitions of @shareable
|
|
311
|
+
if (directiveName === string_constants_1.SHAREABLE) {
|
|
312
|
+
(0, utils_3.getValueOrDefault)(directivesByDirectiveName, directiveName, () => [directiveNode]);
|
|
313
|
+
}
|
|
314
|
+
else {
|
|
315
|
+
(0, utils_3.getValueOrDefault)(directivesByDirectiveName, directiveName, () => []).push(directiveNode);
|
|
316
|
+
}
|
|
317
|
+
if (!(0, utils_3.isNodeKindObject)(node.kind)) {
|
|
215
318
|
continue;
|
|
216
319
|
}
|
|
217
|
-
|
|
320
|
+
this.isParentObjectExternal ||= directiveName === string_constants_1.EXTERNAL;
|
|
321
|
+
this.isParentObjectShareable ||= directiveName === string_constants_1.SHAREABLE;
|
|
322
|
+
}
|
|
323
|
+
return directivesByDirectiveName;
|
|
324
|
+
}
|
|
325
|
+
validateDirective({ data, definitionData, directiveCoords, directiveNode, errorMessages, requiredArgumentNames, }) {
|
|
326
|
+
const directiveName = directiveNode.name.value;
|
|
327
|
+
const parentTypeName = data.kind === graphql_1.Kind.FIELD_DEFINITION ? data.renamedParentTypeName || data.originalParentTypeName : data.name;
|
|
328
|
+
const isAuthenticated = directiveName === string_constants_1.AUTHENTICATED;
|
|
329
|
+
const isOverride = directiveName === string_constants_1.OVERRIDE;
|
|
330
|
+
const isRequiresScopes = directiveName === string_constants_1.REQUIRES_SCOPES;
|
|
331
|
+
if (!directiveNode.arguments || directiveNode.arguments.length < 1) {
|
|
332
|
+
if (definitionData.requiredArgumentNames.size > 0) {
|
|
333
|
+
errorMessages.push((0, errors_1.undefinedRequiredArgumentsErrorMessage)(directiveName, requiredArgumentNames, []));
|
|
334
|
+
}
|
|
335
|
+
if (isAuthenticated) {
|
|
336
|
+
this.handleAuthenticatedDirective(data, parentTypeName);
|
|
337
|
+
}
|
|
338
|
+
return errorMessages;
|
|
339
|
+
}
|
|
340
|
+
const definedArgumentNames = new Set();
|
|
341
|
+
const duplicateArgumentNames = new Set();
|
|
342
|
+
const unexpectedArgumentNames = new Set();
|
|
343
|
+
const requiredScopes = [];
|
|
344
|
+
for (const argumentNode of directiveNode.arguments) {
|
|
345
|
+
const argumentName = argumentNode.name.value;
|
|
346
|
+
if (definedArgumentNames.has(argumentName)) {
|
|
347
|
+
duplicateArgumentNames.add(argumentName);
|
|
218
348
|
continue;
|
|
219
349
|
}
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
}
|
|
350
|
+
definedArgumentNames.add(argumentName);
|
|
351
|
+
const argumentData = definitionData.argumentTypeNodeByArgumentName.get(argumentName);
|
|
352
|
+
if (!argumentData) {
|
|
353
|
+
unexpectedArgumentNames.add(argumentName);
|
|
225
354
|
continue;
|
|
226
355
|
}
|
|
227
|
-
if (
|
|
228
|
-
|
|
356
|
+
if (!this.isArgumentValueValid(argumentData.typeNode, argumentNode.value)) {
|
|
357
|
+
errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(argumentNode.value), `@${directiveName}`, argumentName, (0, merge_1.printTypeNode)(argumentData.typeNode)));
|
|
229
358
|
continue;
|
|
230
359
|
}
|
|
231
|
-
|
|
232
|
-
if (
|
|
233
|
-
|
|
360
|
+
// The directive location validation means the kind check should be unnecessary
|
|
361
|
+
if (isOverride && data.kind === graphql_1.Kind.FIELD_DEFINITION) {
|
|
362
|
+
this.handleOverrideDirective({
|
|
363
|
+
data,
|
|
364
|
+
directiveCoords,
|
|
365
|
+
errorMessages,
|
|
366
|
+
targetSubgraphName: argumentNode.value.value,
|
|
367
|
+
});
|
|
368
|
+
continue;
|
|
369
|
+
}
|
|
370
|
+
if (!isRequiresScopes || argumentName !== string_constants_1.SCOPES) {
|
|
234
371
|
continue;
|
|
235
372
|
}
|
|
236
|
-
|
|
373
|
+
this.handleRequiresScopesDirective({
|
|
374
|
+
directiveCoords,
|
|
375
|
+
// Casts are safe because invalid arguments would short circuit
|
|
376
|
+
orScopes: argumentNode.value.values,
|
|
377
|
+
requiredScopes,
|
|
378
|
+
});
|
|
237
379
|
}
|
|
238
|
-
if (
|
|
239
|
-
|
|
380
|
+
if (duplicateArgumentNames.size > 0) {
|
|
381
|
+
errorMessages.push((0, errors_1.duplicateDirectiveArgumentDefinitionsErrorMessage)([...duplicateArgumentNames]));
|
|
240
382
|
}
|
|
241
|
-
|
|
242
|
-
|
|
383
|
+
if (unexpectedArgumentNames.size > 0) {
|
|
384
|
+
errorMessages.push((0, errors_1.unexpectedDirectiveArgumentErrorMessage)(directiveName, [...unexpectedArgumentNames]));
|
|
385
|
+
}
|
|
386
|
+
const undefinedArgumentNames = (0, utils_3.getEntriesNotInHashSet)(requiredArgumentNames, definedArgumentNames);
|
|
387
|
+
if (undefinedArgumentNames.length > 0) {
|
|
388
|
+
errorMessages.push((0, errors_1.undefinedRequiredArgumentsErrorMessage)(directiveName, requiredArgumentNames, undefinedArgumentNames));
|
|
389
|
+
}
|
|
390
|
+
if (errorMessages.length > 0 || !isRequiresScopes) {
|
|
391
|
+
return errorMessages;
|
|
392
|
+
}
|
|
393
|
+
if (data.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION &&
|
|
394
|
+
data.kind !== graphql_1.Kind.FIELD_DEFINITION &&
|
|
395
|
+
data.kind !== graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
396
|
+
return errorMessages;
|
|
397
|
+
}
|
|
398
|
+
if (data.kind !== graphql_1.Kind.FIELD_DEFINITION) {
|
|
243
399
|
this.leafTypeNamesWithAuthorizationDirectives.add(parentTypeName);
|
|
244
400
|
}
|
|
245
401
|
const parentAuthorizationData = (0, utils_3.getValueOrDefault)(this.authorizationDataByParentTypeName, parentTypeName, () => (0, utils_3.newAuthorizationData)(parentTypeName));
|
|
246
|
-
const authorizationData = (0, utils_3.getAuthorizationDataToUpdate)(parentAuthorizationData, node
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
402
|
+
const authorizationData = (0, utils_3.getAuthorizationDataToUpdate)(parentAuthorizationData, data.node);
|
|
403
|
+
authorizationData.requiredScopes.push(...requiredScopes);
|
|
404
|
+
return errorMessages;
|
|
405
|
+
}
|
|
406
|
+
validateDirectives(data, directiveCoords) {
|
|
407
|
+
const undefinedDirectiveNames = new Set();
|
|
408
|
+
for (const [directiveName, directiveNodes] of data.directivesByDirectiveName) {
|
|
409
|
+
const definitionData = this.directiveDefinitionDataByDirectiveName.get(directiveName);
|
|
410
|
+
if (!definitionData) {
|
|
411
|
+
if (!undefinedDirectiveNames.has(directiveName)) {
|
|
412
|
+
this.errors.push((0, errors_1.undefinedDirectiveError)(directiveName, directiveCoords));
|
|
413
|
+
undefinedDirectiveNames.add(directiveName);
|
|
414
|
+
}
|
|
251
415
|
continue;
|
|
252
416
|
}
|
|
253
|
-
const
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
417
|
+
const definitionErrorMessages = [];
|
|
418
|
+
const directiveLocation = (0, utils_1.nodeKindToDirectiveLocation)(data.kind);
|
|
419
|
+
if (!definitionData.locations.has(directiveLocation)) {
|
|
420
|
+
definitionErrorMessages.push((0, errors_1.invalidDirectiveLocationErrorMessage)(directiveName, directiveLocation));
|
|
257
421
|
}
|
|
258
|
-
|
|
259
|
-
const
|
|
260
|
-
|
|
261
|
-
|
|
422
|
+
if (directiveNodes.length > 1 && !definitionData.isRepeatable) {
|
|
423
|
+
const handledDirectiveNames = (0, utils_3.getValueOrDefault)(this.invalidRepeatedDirectiveNameByCoords, directiveCoords, () => new Set());
|
|
424
|
+
if (!handledDirectiveNames.has(directiveName)) {
|
|
425
|
+
handledDirectiveNames.add(directiveName);
|
|
426
|
+
definitionErrorMessages.push((0, errors_1.invalidRepeatedDirectiveErrorMessage)(directiveName));
|
|
262
427
|
}
|
|
263
|
-
|
|
264
|
-
|
|
428
|
+
}
|
|
429
|
+
const requiredArgumentNames = [...definitionData.requiredArgumentNames];
|
|
430
|
+
for (let i = 0; i < directiveNodes.length; i++) {
|
|
431
|
+
const errorMessages = this.validateDirective({
|
|
432
|
+
data,
|
|
433
|
+
directiveNode: directiveNodes[i],
|
|
434
|
+
definitionData,
|
|
435
|
+
directiveCoords,
|
|
436
|
+
errorMessages: i < 1 ? definitionErrorMessages : [],
|
|
437
|
+
requiredArgumentNames,
|
|
438
|
+
});
|
|
439
|
+
if (errorMessages.length > 0) {
|
|
440
|
+
this.errors.push((0, errors_1.invalidDirectiveError)(directiveName, directiveCoords, (0, utils_3.numberToOrdinal)(i + 1), errorMessages));
|
|
265
441
|
}
|
|
266
442
|
}
|
|
267
443
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
if (!node.directives) {
|
|
275
|
-
return directivesByDirectiveName;
|
|
276
|
-
}
|
|
277
|
-
const entityKeys = new Set();
|
|
278
|
-
for (const directiveNode of node.directives) {
|
|
279
|
-
const errorMessages = (0, utils_4.getDirectiveValidationErrors)(directiveNode, node.kind, directivesByDirectiveName, this.directiveDefinitionByDirectiveName, this.handledRepeatedDirectivesByHostPath, hostPath, isArgument);
|
|
280
|
-
const directiveName = directiveNode.name.value;
|
|
281
|
-
if (errorMessages.length > 0) {
|
|
282
|
-
this.errors.push((0, errors_1.invalidDirectiveError)(directiveName, hostPath, errorMessages));
|
|
283
|
-
continue;
|
|
444
|
+
switch (data.kind) {
|
|
445
|
+
case graphql_1.Kind.ENUM_TYPE_DEFINITION: {
|
|
446
|
+
for (const [enumValueName, enumValueData] of data.enumValueDataByValueName) {
|
|
447
|
+
this.validateDirectives(enumValueData, `${data.name}.${enumValueName}`);
|
|
448
|
+
}
|
|
449
|
+
return;
|
|
284
450
|
}
|
|
285
|
-
|
|
286
|
-
|
|
451
|
+
case graphql_1.Kind.FIELD_DEFINITION: {
|
|
452
|
+
for (const [argumentName, argumentData] of data.argumentDataByArgumentName) {
|
|
453
|
+
this.validateDirectives(argumentData, `${data.originalParentTypeName}.${data.name}(${argumentName}: ...)`);
|
|
454
|
+
}
|
|
455
|
+
return;
|
|
287
456
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
if (entityKeys.has(entityKey)) {
|
|
292
|
-
continue;
|
|
457
|
+
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION: {
|
|
458
|
+
for (const [inputValueName, inputValueData] of data.inputValueDataByValueName) {
|
|
459
|
+
this.validateDirectives(inputValueData, `${data.name}.${inputValueName}`);
|
|
293
460
|
}
|
|
294
|
-
|
|
461
|
+
return;
|
|
295
462
|
}
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
463
|
+
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
464
|
+
// intentional fallthrough
|
|
465
|
+
case graphql_1.Kind.OBJECT_TYPE_DEFINITION: {
|
|
466
|
+
for (const [fieldName, fieldData] of data.fieldDataByFieldName) {
|
|
467
|
+
this.validateDirectives(fieldData, `${data.name}.${fieldName}`);
|
|
468
|
+
}
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
default:
|
|
472
|
+
return;
|
|
300
473
|
}
|
|
301
|
-
return directivesByDirectiveName;
|
|
302
474
|
}
|
|
303
475
|
/* ExtensionType uses a trichotomy rather than a boolean because @extends is still a definition.
|
|
304
476
|
* A definition and another definition with @extends would still be an error, so it cannot be treated
|
|
@@ -338,6 +510,57 @@ class NormalizationFactory {
|
|
|
338
510
|
}
|
|
339
511
|
}
|
|
340
512
|
}
|
|
513
|
+
extractConfigureDescriptionData(data, directiveNode) {
|
|
514
|
+
if (!directiveNode.arguments || directiveNode.arguments.length < 1) {
|
|
515
|
+
if (!data.description) {
|
|
516
|
+
this.invalidConfigureDescriptionNodeDatas.push(data);
|
|
517
|
+
}
|
|
518
|
+
data.configureDescriptionDataBySubgraphName.set(this.subgraphName, {
|
|
519
|
+
propagate: true,
|
|
520
|
+
description: data.description?.value || '',
|
|
521
|
+
});
|
|
522
|
+
return;
|
|
523
|
+
}
|
|
524
|
+
const configureDescriptionData = {
|
|
525
|
+
propagate: true,
|
|
526
|
+
description: data.description?.value || '',
|
|
527
|
+
};
|
|
528
|
+
for (const argument of directiveNode.arguments) {
|
|
529
|
+
switch (argument.name.value) {
|
|
530
|
+
case string_constants_1.PROPAGATE: {
|
|
531
|
+
if (argument.value.kind != graphql_1.Kind.BOOLEAN) {
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
configureDescriptionData.propagate = argument.value.value;
|
|
535
|
+
break;
|
|
536
|
+
}
|
|
537
|
+
case string_constants_1.DESCRIPTION_OVERRIDE: {
|
|
538
|
+
if (argument.value.kind != graphql_1.Kind.STRING) {
|
|
539
|
+
return;
|
|
540
|
+
}
|
|
541
|
+
configureDescriptionData.description = argument.value.value;
|
|
542
|
+
break;
|
|
543
|
+
}
|
|
544
|
+
default: {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
if (!data.description && !configureDescriptionData.description) {
|
|
550
|
+
this.invalidConfigureDescriptionNodeDatas.push(data);
|
|
551
|
+
}
|
|
552
|
+
data.configureDescriptionDataBySubgraphName.set(this.subgraphName, configureDescriptionData);
|
|
553
|
+
}
|
|
554
|
+
extractConfigureDescriptionsData(data) {
|
|
555
|
+
const configureDescriptionNodes = data.directivesByDirectiveName.get(string_constants_1.CONFIGURE_DESCRIPTION);
|
|
556
|
+
if (configureDescriptionNodes && configureDescriptionNodes.length == 1) {
|
|
557
|
+
this.extractConfigureDescriptionData(data, configureDescriptionNodes[0]);
|
|
558
|
+
}
|
|
559
|
+
// TODO configureChildDescriptions will be added in another PR
|
|
560
|
+
// const configureChildDescriptionsNodes = data.directivesByDirectiveName.get(CONFIGURE_CHILD_DESCRIPTIONS);
|
|
561
|
+
// if (configureChildDescriptionsNodes && configureChildDescriptionsNodes.length == 1) {
|
|
562
|
+
// }
|
|
563
|
+
}
|
|
341
564
|
extractImplementedInterfaceTypeNames(node, implementedInterfaceTypeNames) {
|
|
342
565
|
if (!node.interfaces) {
|
|
343
566
|
return implementedInterfaceTypeNames;
|
|
@@ -353,13 +576,14 @@ class NormalizationFactory {
|
|
|
353
576
|
}
|
|
354
577
|
return implementedInterfaceTypeNames;
|
|
355
578
|
}
|
|
356
|
-
updateCompositeOutputDataByNode(node,
|
|
357
|
-
this.setParentDataExtensionType(
|
|
358
|
-
this.extractImplementedInterfaceTypeNames(node,
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
579
|
+
updateCompositeOutputDataByNode(node, data, extensionType) {
|
|
580
|
+
this.setParentDataExtensionType(data, extensionType);
|
|
581
|
+
this.extractImplementedInterfaceTypeNames(node, data.implementedInterfaceTypeNames);
|
|
582
|
+
data.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
583
|
+
this.extractConfigureDescriptionsData(data);
|
|
584
|
+
data.isEntity ||= data.directivesByDirectiveName.has(string_constants_1.KEY);
|
|
585
|
+
data.isInaccessible ||= data.directivesByDirectiveName.has(string_constants_1.INACCESSIBLE);
|
|
586
|
+
data.subgraphNames.add(this.subgraphName);
|
|
363
587
|
}
|
|
364
588
|
addConcreteTypeNamesForImplementedInterfaces(interfaceTypeNames, concreteTypeName) {
|
|
365
589
|
for (const interfaceName of interfaceTypeNames) {
|
|
@@ -367,10 +591,196 @@ class NormalizationFactory {
|
|
|
367
591
|
this.internalGraph.addEdge(this.internalGraph.addOrUpdateNode(interfaceName, { isAbstract: true }), this.internalGraph.addOrUpdateNode(concreteTypeName), concreteTypeName, true);
|
|
368
592
|
}
|
|
369
593
|
}
|
|
594
|
+
extractArguments(argumentDataByArgumentName, node) {
|
|
595
|
+
if (!node.arguments?.length) {
|
|
596
|
+
return argumentDataByArgumentName;
|
|
597
|
+
}
|
|
598
|
+
const fieldName = node.name.value;
|
|
599
|
+
const originalFieldPath = `${this.originalParentTypeName}.${fieldName}`;
|
|
600
|
+
const renamedFieldPath = `${this.renamedParentTypeName}.${fieldName}`;
|
|
601
|
+
this.parentsWithChildArguments.add(this.originalParentTypeName);
|
|
602
|
+
const duplicatedArguments = new Set();
|
|
603
|
+
for (const argumentNode of node.arguments) {
|
|
604
|
+
const argumentName = argumentNode.name.value;
|
|
605
|
+
if (argumentDataByArgumentName.has(argumentName)) {
|
|
606
|
+
duplicatedArguments.add(argumentName);
|
|
607
|
+
continue;
|
|
608
|
+
}
|
|
609
|
+
this.addInputValueDataByNode(argumentDataByArgumentName, argumentNode, `${originalFieldPath}(${argumentName}: ...)`, `${renamedFieldPath}(${argumentName}: ...)`);
|
|
610
|
+
}
|
|
611
|
+
if (duplicatedArguments.size > 0) {
|
|
612
|
+
this.errors.push((0, errors_1.duplicateArgumentsError)(originalFieldPath, [...duplicatedArguments]));
|
|
613
|
+
}
|
|
614
|
+
return argumentDataByArgumentName;
|
|
615
|
+
}
|
|
616
|
+
addPersistedDirectiveDefinitionDataByNode(persistedDirectiveDefinitionDataByDirectiveName, node, executableLocations) {
|
|
617
|
+
const name = node.name.value;
|
|
618
|
+
const argumentDataByArgumentName = new Map();
|
|
619
|
+
for (const argumentNode of node.arguments || []) {
|
|
620
|
+
const originalPath = `@${name}(${argumentNode.name.value}: ...)`;
|
|
621
|
+
this.addInputValueDataByNode(argumentDataByArgumentName, argumentNode, originalPath, originalPath);
|
|
622
|
+
}
|
|
623
|
+
persistedDirectiveDefinitionDataByDirectiveName.set(name, {
|
|
624
|
+
argumentDataByArgumentName,
|
|
625
|
+
executableLocations,
|
|
626
|
+
name,
|
|
627
|
+
repeatable: node.repeatable,
|
|
628
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
629
|
+
description: (0, utils_1.formatDescription)(node.description),
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
extractDirectiveLocations(node, errorMessages) {
|
|
633
|
+
const locations = new Set();
|
|
634
|
+
const handledLocations = new Set();
|
|
635
|
+
for (const locationNode of node.locations) {
|
|
636
|
+
const locationName = locationNode.value;
|
|
637
|
+
if (handledLocations.has(locationName)) {
|
|
638
|
+
continue;
|
|
639
|
+
}
|
|
640
|
+
if (!string_constants_1.EXECUTABLE_DIRECTIVE_LOCATIONS.has(locationName) && !string_constants_1.TYPE_SYSTEM_DIRECTIVE_LOCATIONS.has(locationName)) {
|
|
641
|
+
errorMessages.push((0, errors_1.invalidDirectiveDefinitionLocationErrorMessage)(locationName));
|
|
642
|
+
handledLocations.add(locationName);
|
|
643
|
+
continue;
|
|
644
|
+
}
|
|
645
|
+
if (locations.has(locationName)) {
|
|
646
|
+
errorMessages.push((0, errors_1.duplicateDirectiveDefinitionLocationErrorMessage)(locationName));
|
|
647
|
+
handledLocations.add(locationName);
|
|
648
|
+
continue;
|
|
649
|
+
}
|
|
650
|
+
locations.add(locationName);
|
|
651
|
+
}
|
|
652
|
+
return locations;
|
|
653
|
+
}
|
|
654
|
+
extractArgumentData(argumentNodes, errorMessages) {
|
|
655
|
+
const argumentTypeNodeByArgumentName = new Map();
|
|
656
|
+
const optionalArgumentNames = new Set();
|
|
657
|
+
const requiredArgumentNames = new Set();
|
|
658
|
+
const output = {
|
|
659
|
+
argumentTypeNodeByArgumentName,
|
|
660
|
+
optionalArgumentNames,
|
|
661
|
+
requiredArgumentNames,
|
|
662
|
+
};
|
|
663
|
+
if (!argumentNodes) {
|
|
664
|
+
return output;
|
|
665
|
+
}
|
|
666
|
+
const duplicateArgumentNames = new Set();
|
|
667
|
+
for (const argumentNode of argumentNodes) {
|
|
668
|
+
const name = argumentNode.name.value;
|
|
669
|
+
if (argumentTypeNodeByArgumentName.has(name)) {
|
|
670
|
+
duplicateArgumentNames.add(name);
|
|
671
|
+
continue;
|
|
672
|
+
}
|
|
673
|
+
if (argumentNode.defaultValue) {
|
|
674
|
+
optionalArgumentNames.add(name);
|
|
675
|
+
}
|
|
676
|
+
if ((0, utils_4.isTypeRequired)(argumentNode.type) && !argumentNode.defaultValue) {
|
|
677
|
+
requiredArgumentNames.add(name);
|
|
678
|
+
}
|
|
679
|
+
argumentTypeNodeByArgumentName.set(name, {
|
|
680
|
+
name,
|
|
681
|
+
typeNode: argumentNode.type,
|
|
682
|
+
defaultValue: argumentNode.defaultValue,
|
|
683
|
+
});
|
|
684
|
+
}
|
|
685
|
+
if (duplicateArgumentNames.size > 0) {
|
|
686
|
+
errorMessages.push((0, errors_1.duplicateDirectiveDefinitionArgumentErrorMessage)([...duplicateArgumentNames]));
|
|
687
|
+
}
|
|
688
|
+
return output;
|
|
689
|
+
}
|
|
690
|
+
// returns true if the directive is custom; otherwise, false
|
|
691
|
+
addDirectiveDefinitionDataByNode(node) {
|
|
692
|
+
const name = node.name.value;
|
|
693
|
+
if (this.definedDirectiveNames.has(name)) {
|
|
694
|
+
this.errors.push((0, errors_1.duplicateDirectiveDefinitionError)(name));
|
|
695
|
+
return false;
|
|
696
|
+
}
|
|
697
|
+
this.definedDirectiveNames.add(name);
|
|
698
|
+
this.directiveDefinitionByDirectiveName.set(name, node);
|
|
699
|
+
// Normalize federation directives by replacing them with predefined definitions
|
|
700
|
+
if (constants_1.V2_DIRECTIVE_DEFINITION_BY_DIRECTIVE_NAME.has(name)) {
|
|
701
|
+
this.isSubgraphVersionTwo = true;
|
|
702
|
+
return false;
|
|
703
|
+
}
|
|
704
|
+
if (constants_1.ALL_IN_BUILT_DIRECTIVE_NAMES.has(name)) {
|
|
705
|
+
return false;
|
|
706
|
+
}
|
|
707
|
+
const errorMessages = [];
|
|
708
|
+
const { argumentTypeNodeByArgumentName, optionalArgumentNames, requiredArgumentNames } = this.extractArgumentData(node.arguments, errorMessages);
|
|
709
|
+
this.directiveDefinitionDataByDirectiveName.set(name, {
|
|
710
|
+
argumentTypeNodeByArgumentName,
|
|
711
|
+
isRepeatable: node.repeatable,
|
|
712
|
+
locations: this.extractDirectiveLocations(node, errorMessages),
|
|
713
|
+
name,
|
|
714
|
+
node,
|
|
715
|
+
optionalArgumentNames,
|
|
716
|
+
requiredArgumentNames,
|
|
717
|
+
});
|
|
718
|
+
if (errorMessages.length > 0) {
|
|
719
|
+
this.errors.push((0, errors_1.invalidDirectiveDefinitionError)(name, errorMessages));
|
|
720
|
+
}
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
addFieldDataByNode(fieldDataByFieldName, node, argumentDataByArgumentName, directivesByDirectiveName) {
|
|
724
|
+
const name = node.name.value;
|
|
725
|
+
const fieldPath = `${this.originalParentTypeName}.${name}`;
|
|
726
|
+
const isNodeExternalOrShareableResult = (0, utils_4.isNodeExternalOrShareable)(node, !this.isSubgraphVersionTwo, directivesByDirectiveName);
|
|
727
|
+
const fieldData = {
|
|
728
|
+
argumentDataByArgumentName: argumentDataByArgumentName,
|
|
729
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
730
|
+
isExternalBySubgraphName: new Map([
|
|
731
|
+
[this.subgraphName, isNodeExternalOrShareableResult.isExternal],
|
|
732
|
+
]),
|
|
733
|
+
isInaccessible: directivesByDirectiveName.has(string_constants_1.INACCESSIBLE),
|
|
734
|
+
isShareableBySubgraphName: new Map([
|
|
735
|
+
[this.subgraphName, isNodeExternalOrShareableResult.isShareable],
|
|
736
|
+
]),
|
|
737
|
+
kind: graphql_1.Kind.FIELD_DEFINITION,
|
|
738
|
+
name,
|
|
739
|
+
namedTypeName: (0, ast_1.getTypeNodeNamedTypeName)(node.type),
|
|
740
|
+
node: (0, ast_1.getMutableFieldNode)(node, fieldPath, this.errors),
|
|
741
|
+
originalParentTypeName: this.originalParentTypeName,
|
|
742
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
743
|
+
renamedParentTypeName: this.renamedParentTypeName || this.originalParentTypeName,
|
|
744
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
745
|
+
type: (0, ast_1.getMutableTypeNode)(node.type, fieldPath, this.errors),
|
|
746
|
+
directivesByDirectiveName,
|
|
747
|
+
description: (0, utils_1.formatDescription)(node.description),
|
|
748
|
+
};
|
|
749
|
+
this.extractConfigureDescriptionsData(fieldData);
|
|
750
|
+
fieldDataByFieldName.set(name, fieldData);
|
|
751
|
+
return fieldData;
|
|
752
|
+
}
|
|
753
|
+
addInputValueDataByNode(inputValueDataByValueName, node, originalPath, renamedPath) {
|
|
754
|
+
const name = node.name.value;
|
|
755
|
+
// Only arguments have renamed paths
|
|
756
|
+
const isArgument = !!renamedPath;
|
|
757
|
+
if (node.defaultValue && !(0, utils_4.areDefaultValuesCompatible)(node.type, node.defaultValue)) {
|
|
758
|
+
this.errors.push((0, errors_1.incompatibleInputValueDefaultValueTypeError)((isArgument ? string_constants_1.ARGUMENT : string_constants_1.INPUT_FIELD) + ` "${name}"`, originalPath, (0, merge_1.printTypeNode)(node.type), (0, graphql_1.print)(node.defaultValue)));
|
|
759
|
+
}
|
|
760
|
+
const inputValueData = {
|
|
761
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
762
|
+
directivesByDirectiveName: this.extractDirectives(node, new Map()),
|
|
763
|
+
includeDefaultValue: !!node.defaultValue,
|
|
764
|
+
isArgument,
|
|
765
|
+
kind: isArgument ? graphql_1.Kind.ARGUMENT : graphql_1.Kind.INPUT_VALUE_DEFINITION,
|
|
766
|
+
name,
|
|
767
|
+
node: (0, ast_1.getMutableInputValueNode)(node, originalPath, this.errors),
|
|
768
|
+
originalPath,
|
|
769
|
+
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
770
|
+
renamedPath: renamedPath || originalPath,
|
|
771
|
+
requiredSubgraphNames: new Set((0, utils_4.isTypeRequired)(node.type) ? [this.subgraphName] : []),
|
|
772
|
+
subgraphNames: new Set([this.subgraphName]),
|
|
773
|
+
type: (0, ast_1.getMutableTypeNode)(node.type, originalPath, this.errors),
|
|
774
|
+
defaultValue: node.defaultValue, // TODO validate
|
|
775
|
+
description: (0, utils_1.formatDescription)(node.description),
|
|
776
|
+
};
|
|
777
|
+
this.extractConfigureDescriptionsData(inputValueData);
|
|
778
|
+
inputValueDataByValueName.set(name, inputValueData);
|
|
779
|
+
}
|
|
370
780
|
upsertInterfaceDataByNode(node, isRealExtension = false) {
|
|
371
781
|
const typeName = node.name.value;
|
|
372
782
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
373
|
-
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map()
|
|
783
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
374
784
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
375
785
|
const entityInterfaceData = this.entityInterfaceDataByTypeName.get(typeName);
|
|
376
786
|
if (entityInterfaceData && node.fields) {
|
|
@@ -383,10 +793,11 @@ class NormalizationFactory {
|
|
|
383
793
|
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
384
794
|
return;
|
|
385
795
|
}
|
|
386
|
-
this.updateCompositeOutputDataByNode(node, parentData,
|
|
796
|
+
this.updateCompositeOutputDataByNode(node, parentData, extensionType);
|
|
387
797
|
return;
|
|
388
798
|
}
|
|
389
|
-
|
|
799
|
+
const newParentData = {
|
|
800
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
390
801
|
directivesByDirectiveName,
|
|
391
802
|
extensionType,
|
|
392
803
|
fieldDataByFieldName: new Map(),
|
|
@@ -399,7 +810,9 @@ class NormalizationFactory {
|
|
|
399
810
|
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
400
811
|
subgraphNames: new Set([this.subgraphName]),
|
|
401
812
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
402
|
-
}
|
|
813
|
+
};
|
|
814
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
815
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
403
816
|
}
|
|
404
817
|
getRenamedRootTypeName(typeName) {
|
|
405
818
|
const operationTypeNode = this.operationTypeNodeByTypeName.get(typeName);
|
|
@@ -428,7 +841,7 @@ class NormalizationFactory {
|
|
|
428
841
|
upsertObjectDataByNode(node, isRealExtension = false) {
|
|
429
842
|
const typeName = node.name.value;
|
|
430
843
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
431
|
-
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map()
|
|
844
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
432
845
|
const isRootType = this.isTypeNameRootType(typeName);
|
|
433
846
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName, isRootType);
|
|
434
847
|
this.addInterfaceObjectFieldsByNode(node);
|
|
@@ -437,13 +850,14 @@ class NormalizationFactory {
|
|
|
437
850
|
this.errors.push((0, errors_1.multipleNamedTypeDefinitionError)(typeName, (0, utils_3.kindToTypeString)(parentData.kind), (0, utils_3.kindToConvertedTypeString)(node.kind)));
|
|
438
851
|
return;
|
|
439
852
|
}
|
|
440
|
-
this.updateCompositeOutputDataByNode(node, parentData,
|
|
853
|
+
this.updateCompositeOutputDataByNode(node, parentData, extensionType);
|
|
441
854
|
this.addConcreteTypeNamesForImplementedInterfaces(parentData.implementedInterfaceTypeNames, typeName);
|
|
442
855
|
return;
|
|
443
856
|
}
|
|
444
857
|
const implementedInterfaceTypeNames = this.extractImplementedInterfaceTypeNames(node, new Set());
|
|
445
858
|
this.addConcreteTypeNamesForImplementedInterfaces(implementedInterfaceTypeNames, typeName);
|
|
446
|
-
|
|
859
|
+
const newParentData = {
|
|
860
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
447
861
|
directivesByDirectiveName,
|
|
448
862
|
extensionType,
|
|
449
863
|
fieldDataByFieldName: new Map(),
|
|
@@ -458,13 +872,15 @@ class NormalizationFactory {
|
|
|
458
872
|
renamedTypeName: this.getRenamedRootTypeName(typeName),
|
|
459
873
|
subgraphNames: new Set([this.subgraphName]),
|
|
460
874
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
461
|
-
}
|
|
875
|
+
};
|
|
876
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
877
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
462
878
|
}
|
|
463
879
|
upsertEnumDataByNode(node, isRealExtension = false) {
|
|
464
880
|
const typeName = node.name.value;
|
|
465
881
|
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
466
882
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
467
|
-
const directivesByDirectiveName = this.
|
|
883
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
468
884
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
469
885
|
if (parentData) {
|
|
470
886
|
if (parentData.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION) {
|
|
@@ -474,10 +890,12 @@ class NormalizationFactory {
|
|
|
474
890
|
this.setParentDataExtensionType(parentData, extensionType);
|
|
475
891
|
parentData.subgraphNames.add(this.subgraphName);
|
|
476
892
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
893
|
+
this.extractConfigureDescriptionsData(parentData);
|
|
477
894
|
return;
|
|
478
895
|
}
|
|
479
|
-
|
|
896
|
+
const newParentData = {
|
|
480
897
|
appearances: 1,
|
|
898
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
481
899
|
directivesByDirectiveName,
|
|
482
900
|
extensionType,
|
|
483
901
|
enumValueDataByValueName: new Map(),
|
|
@@ -487,12 +905,14 @@ class NormalizationFactory {
|
|
|
487
905
|
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
488
906
|
subgraphNames: new Set([this.subgraphName]),
|
|
489
907
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
490
|
-
}
|
|
908
|
+
};
|
|
909
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
910
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
491
911
|
}
|
|
492
912
|
upsertInputObjectByNode(node, isRealExtension = false) {
|
|
493
913
|
const typeName = node.name.value;
|
|
494
914
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
495
|
-
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map()
|
|
915
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
496
916
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
497
917
|
if (parentData) {
|
|
498
918
|
if (parentData.kind !== graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION) {
|
|
@@ -503,9 +923,11 @@ class NormalizationFactory {
|
|
|
503
923
|
parentData.isInaccessible ||= directivesByDirectiveName.has(string_constants_1.INACCESSIBLE);
|
|
504
924
|
parentData.subgraphNames.add(this.subgraphName);
|
|
505
925
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
926
|
+
this.extractConfigureDescriptionsData(parentData);
|
|
506
927
|
return;
|
|
507
928
|
}
|
|
508
|
-
|
|
929
|
+
const newParentData = {
|
|
930
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
509
931
|
directivesByDirectiveName,
|
|
510
932
|
extensionType,
|
|
511
933
|
inputValueDataByValueName: new Map(),
|
|
@@ -516,13 +938,15 @@ class NormalizationFactory {
|
|
|
516
938
|
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
517
939
|
subgraphNames: new Set([this.subgraphName]),
|
|
518
940
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
519
|
-
}
|
|
941
|
+
};
|
|
942
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
943
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
520
944
|
}
|
|
521
945
|
upsertScalarByNode(node, isRealExtension = false) {
|
|
522
946
|
const typeName = node.name.value;
|
|
523
947
|
this.internalGraph.addOrUpdateNode(typeName, { isLeaf: true });
|
|
524
948
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
525
|
-
const directivesByDirectiveName = this.
|
|
949
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
526
950
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
527
951
|
if (parentData) {
|
|
528
952
|
if (parentData.kind !== graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
@@ -531,9 +955,11 @@ class NormalizationFactory {
|
|
|
531
955
|
}
|
|
532
956
|
this.setParentDataExtensionType(parentData, extensionType);
|
|
533
957
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
958
|
+
this.extractConfigureDescriptionsData(parentData);
|
|
534
959
|
return;
|
|
535
960
|
}
|
|
536
|
-
|
|
961
|
+
const newParentData = {
|
|
962
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
537
963
|
directivesByDirectiveName,
|
|
538
964
|
extensionType,
|
|
539
965
|
kind: graphql_1.Kind.SCALAR_TYPE_DEFINITION,
|
|
@@ -541,7 +967,9 @@ class NormalizationFactory {
|
|
|
541
967
|
node: (0, ast_1.getMutableScalarNode)(node.name),
|
|
542
968
|
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
543
969
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
544
|
-
}
|
|
970
|
+
};
|
|
971
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
972
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
545
973
|
}
|
|
546
974
|
extractUnionMembers(node, membersByMemberTypeName) {
|
|
547
975
|
if (!node.types) {
|
|
@@ -571,7 +999,7 @@ class NormalizationFactory {
|
|
|
571
999
|
upsertUnionByNode(node, isRealExtension = false) {
|
|
572
1000
|
const typeName = node.name.value;
|
|
573
1001
|
const parentData = this.parentDefinitionDataByTypeName.get(typeName);
|
|
574
|
-
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map()
|
|
1002
|
+
const directivesByDirectiveName = this.extractDirectives(node, parentData?.directivesByDirectiveName || new Map());
|
|
575
1003
|
const extensionType = this.getNodeExtensionType(isRealExtension, directivesByDirectiveName);
|
|
576
1004
|
// Also adds the concrete type name edges to the internal graph
|
|
577
1005
|
this.addConcreteTypeNamesForUnion(node);
|
|
@@ -583,9 +1011,11 @@ class NormalizationFactory {
|
|
|
583
1011
|
this.setParentDataExtensionType(parentData, extensionType);
|
|
584
1012
|
this.extractUnionMembers(node, parentData.memberByMemberTypeName);
|
|
585
1013
|
parentData.description ||= (0, utils_1.formatDescription)('description' in node ? node.description : undefined);
|
|
1014
|
+
this.extractConfigureDescriptionsData(parentData);
|
|
586
1015
|
return;
|
|
587
1016
|
}
|
|
588
|
-
|
|
1017
|
+
const newParentData = {
|
|
1018
|
+
configureDescriptionDataBySubgraphName: new Map(),
|
|
589
1019
|
directivesByDirectiveName,
|
|
590
1020
|
extensionType,
|
|
591
1021
|
kind: graphql_1.Kind.UNION_TYPE_DEFINITION,
|
|
@@ -594,7 +1024,9 @@ class NormalizationFactory {
|
|
|
594
1024
|
node: (0, ast_1.getMutableUnionNode)(node.name),
|
|
595
1025
|
persistedDirectivesData: (0, utils_4.newPersistedDirectivesData)(),
|
|
596
1026
|
description: (0, utils_1.formatDescription)('description' in node ? node.description : undefined),
|
|
597
|
-
}
|
|
1027
|
+
};
|
|
1028
|
+
this.extractConfigureDescriptionsData(newParentData);
|
|
1029
|
+
this.parentDefinitionDataByTypeName.set(typeName, newParentData);
|
|
598
1030
|
}
|
|
599
1031
|
extractKeyFieldSets(node, keyFieldSetData) {
|
|
600
1032
|
const isUnresolvableByRawKeyFieldSet = keyFieldSetData.isUnresolvableByKeyFieldSet;
|
|
@@ -604,13 +1036,12 @@ class NormalizationFactory {
|
|
|
604
1036
|
this.errors.push((0, errors_1.expectedEntityError)(parentTypeName));
|
|
605
1037
|
return;
|
|
606
1038
|
}
|
|
607
|
-
|
|
1039
|
+
// validation happens elsewhere
|
|
608
1040
|
for (const directive of node.directives) {
|
|
609
1041
|
if (directive.name.value !== string_constants_1.KEY) {
|
|
610
1042
|
continue;
|
|
611
1043
|
}
|
|
612
1044
|
if (!directive.arguments || directive.arguments.length < 1) {
|
|
613
|
-
errorMessages.push((0, errors_1.undefinedRequiredArgumentsErrorMessage)(string_constants_1.KEY, parentTypeName, [string_constants_1.FIELDS]));
|
|
614
1045
|
continue;
|
|
615
1046
|
}
|
|
616
1047
|
let keyFieldSet;
|
|
@@ -628,7 +1059,6 @@ class NormalizationFactory {
|
|
|
628
1059
|
}
|
|
629
1060
|
if (arg.value.kind !== graphql_1.Kind.STRING) {
|
|
630
1061
|
keyFieldSet = undefined;
|
|
631
|
-
errorMessages.push((0, errors_1.invalidKeyDirectiveArgumentErrorMessage)(arg.value.kind));
|
|
632
1062
|
break;
|
|
633
1063
|
}
|
|
634
1064
|
keyFieldSet = arg.value.value;
|
|
@@ -637,9 +1067,6 @@ class NormalizationFactory {
|
|
|
637
1067
|
isUnresolvableByRawKeyFieldSet.set(keyFieldSet, isUnresolvable);
|
|
638
1068
|
}
|
|
639
1069
|
}
|
|
640
|
-
if (errorMessages.length) {
|
|
641
|
-
this.errors.push((0, errors_1.invalidKeyDirectivesError)(parentTypeName, errorMessages));
|
|
642
|
-
}
|
|
643
1070
|
}
|
|
644
1071
|
validateInterfaceImplementations(data) {
|
|
645
1072
|
if (data.implementedInterfaceTypeNames.size < 1) {
|
|
@@ -745,20 +1172,40 @@ class NormalizationFactory {
|
|
|
745
1172
|
this.errors.push((0, errors_1.invalidInterfaceImplementationError)(data.name, (0, utils_3.kindToTypeString)(data.kind), implementationErrorsMap));
|
|
746
1173
|
}
|
|
747
1174
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
1175
|
+
handleAuthenticatedDirective(data, parentTypeName) {
|
|
1176
|
+
if (data.kind !== graphql_1.Kind.ENUM_TYPE_DEFINITION &&
|
|
1177
|
+
data.kind !== graphql_1.Kind.FIELD_DEFINITION &&
|
|
1178
|
+
data.kind !== graphql_1.Kind.SCALAR_TYPE_DEFINITION) {
|
|
752
1179
|
return;
|
|
753
1180
|
}
|
|
754
|
-
|
|
1181
|
+
if (data.kind !== graphql_1.Kind.FIELD_DEFINITION) {
|
|
1182
|
+
this.leafTypeNamesWithAuthorizationDirectives.add(parentTypeName);
|
|
1183
|
+
}
|
|
1184
|
+
const parentAuthorizationData = (0, utils_3.getValueOrDefault)(this.authorizationDataByParentTypeName, parentTypeName, () => (0, utils_3.newAuthorizationData)(parentTypeName));
|
|
1185
|
+
(0, utils_3.getAuthorizationDataToUpdate)(parentAuthorizationData, data.node).requiresAuthentication = true;
|
|
1186
|
+
}
|
|
1187
|
+
handleOverrideDirective({ data, directiveCoords, errorMessages, targetSubgraphName }) {
|
|
755
1188
|
if (targetSubgraphName === this.subgraphName) {
|
|
756
|
-
errorMessages.push((0, errors_1.equivalentSourceAndTargetOverrideErrorMessage)(targetSubgraphName,
|
|
1189
|
+
errorMessages.push((0, errors_1.equivalentSourceAndTargetOverrideErrorMessage)(targetSubgraphName, directiveCoords));
|
|
757
1190
|
return;
|
|
758
1191
|
}
|
|
759
1192
|
const overrideDataForSubgraph = (0, utils_3.getValueOrDefault)(this.overridesByTargetSubgraphName, targetSubgraphName, () => new Map());
|
|
760
|
-
|
|
761
|
-
|
|
1193
|
+
(0, utils_3.getValueOrDefault)(overrideDataForSubgraph, data.renamedParentTypeName || data.originalParentTypeName, () => new Set()).add(data.name);
|
|
1194
|
+
}
|
|
1195
|
+
handleRequiresScopesDirective({ directiveCoords, orScopes, requiredScopes }) {
|
|
1196
|
+
if (orScopes.length > utils_3.maxOrScopes) {
|
|
1197
|
+
this.invalidOrScopesHostPaths.add(directiveCoords);
|
|
1198
|
+
return;
|
|
1199
|
+
}
|
|
1200
|
+
for (const scopes of orScopes) {
|
|
1201
|
+
const andScopes = new Set();
|
|
1202
|
+
for (const scope of scopes.values) {
|
|
1203
|
+
andScopes.add(scope.value);
|
|
1204
|
+
}
|
|
1205
|
+
if (andScopes.size > 0) {
|
|
1206
|
+
requiredScopes.push(andScopes);
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
762
1209
|
}
|
|
763
1210
|
getKafkaPublishConfiguration(directive, argumentDataByArgumentName, errorMessages) {
|
|
764
1211
|
const topics = [];
|
|
@@ -869,7 +1316,7 @@ class NormalizationFactory {
|
|
|
869
1316
|
switch (argumentNode.name.value) {
|
|
870
1317
|
case string_constants_1.SUBJECTS: {
|
|
871
1318
|
if (argumentNode.value.kind !== graphql_1.Kind.LIST) {
|
|
872
|
-
errorMessages.push(
|
|
1319
|
+
// errorMessages.push(invalidEventSubjectsErrorMessage(SUBJECTS));
|
|
873
1320
|
continue;
|
|
874
1321
|
}
|
|
875
1322
|
for (const value of argumentNode.value.values) {
|
|
@@ -939,15 +1386,16 @@ class NormalizationFactory {
|
|
|
939
1386
|
break;
|
|
940
1387
|
case string_constants_1.CONSUMER_INACTIVE_THRESHOLD:
|
|
941
1388
|
if (field.value.kind != graphql_1.Kind.INT) {
|
|
942
|
-
errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)(
|
|
1389
|
+
errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(field.value), 'edfs__NatsStreamConfiguration', `consumerInactiveThreshold`, string_constants_1.INT_SCALAR));
|
|
943
1390
|
isValid = false;
|
|
944
1391
|
continue;
|
|
945
1392
|
}
|
|
1393
|
+
// It should not be possible for this to error
|
|
946
1394
|
try {
|
|
947
1395
|
consumerInactiveThreshold = parseInt(field.value.value, 10);
|
|
948
1396
|
}
|
|
949
1397
|
catch (e) {
|
|
950
|
-
errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)(
|
|
1398
|
+
errorMessages.push((0, errors_1.invalidArgumentValueErrorMessage)((0, graphql_1.print)(field.value), 'edfs__NatsStreamConfiguration', `consumerInactiveThreshold`, string_constants_1.INT_SCALAR));
|
|
951
1399
|
isValid = false;
|
|
952
1400
|
}
|
|
953
1401
|
break;
|
|
@@ -1250,6 +1698,11 @@ class NormalizationFactory {
|
|
|
1250
1698
|
this.parentDefinitionDataByTypeName.delete(string_constants_1.EDFS_NATS_STREAM_CONFIGURATION);
|
|
1251
1699
|
definitions.push(constants_1.EDFS_NATS_STREAM_CONFIGURATION_DEFINITION);
|
|
1252
1700
|
}
|
|
1701
|
+
if (this.referencedDirectiveNames.has(string_constants_1.LINK)) {
|
|
1702
|
+
definitions.push(constants_1.LINK_DEFINITION);
|
|
1703
|
+
definitions.push(constants_1.LINK_IMPORT_DEFINITION);
|
|
1704
|
+
definitions.push(constants_1.LINK_PURPOSE_DEFINITION);
|
|
1705
|
+
}
|
|
1253
1706
|
if (invalidEventsDirectiveDataByRootFieldPath.size > 0) {
|
|
1254
1707
|
errorMessages.push((0, errors_1.invalidRootTypeFieldEventsDirectivesErrorMessage)(invalidEventsDirectiveDataByRootFieldPath));
|
|
1255
1708
|
}
|
|
@@ -1327,6 +1780,85 @@ class NormalizationFactory {
|
|
|
1327
1780
|
this.validateAndAddKeyToConfiguration(parentData, keyFieldSetData);
|
|
1328
1781
|
}
|
|
1329
1782
|
}
|
|
1783
|
+
getValidFlattenedDirectiveArray(directivesByDirectiveName, directiveCoords) {
|
|
1784
|
+
const flattenedArray = [];
|
|
1785
|
+
for (const [directiveName, directiveNodes] of directivesByDirectiveName) {
|
|
1786
|
+
const directiveDefinition = this.directiveDefinitionDataByDirectiveName.get(directiveName);
|
|
1787
|
+
if (!directiveDefinition) {
|
|
1788
|
+
continue;
|
|
1789
|
+
}
|
|
1790
|
+
if (!directiveDefinition.isRepeatable && directiveNodes.length > 1) {
|
|
1791
|
+
const handledDirectiveNames = (0, utils_3.getValueOrDefault)(this.invalidRepeatedDirectiveNameByCoords, directiveCoords, () => new Set());
|
|
1792
|
+
if (!handledDirectiveNames.has(directiveName)) {
|
|
1793
|
+
handledDirectiveNames.add(directiveName);
|
|
1794
|
+
this.errors.push((0, errors_1.invalidDirectiveError)(directiveName, directiveCoords, '1st', [
|
|
1795
|
+
(0, errors_1.invalidRepeatedDirectiveErrorMessage)(directiveName),
|
|
1796
|
+
]));
|
|
1797
|
+
}
|
|
1798
|
+
continue;
|
|
1799
|
+
}
|
|
1800
|
+
if (directiveName !== string_constants_1.KEY) {
|
|
1801
|
+
flattenedArray.push(...directiveNodes);
|
|
1802
|
+
continue;
|
|
1803
|
+
}
|
|
1804
|
+
const normalizedDirectiveNodes = [];
|
|
1805
|
+
const entityKeys = new Set();
|
|
1806
|
+
for (let i = 0; i < directiveNodes.length; i++) {
|
|
1807
|
+
const keyDirectiveNode = directiveNodes[i];
|
|
1808
|
+
const directiveValue = keyDirectiveNode.arguments[0].value;
|
|
1809
|
+
if (directiveValue.kind !== graphql_1.Kind.STRING) {
|
|
1810
|
+
continue;
|
|
1811
|
+
}
|
|
1812
|
+
const entityKey = directiveValue.value;
|
|
1813
|
+
if (entityKeys.has(entityKey)) {
|
|
1814
|
+
continue;
|
|
1815
|
+
}
|
|
1816
|
+
entityKeys.add(entityKey);
|
|
1817
|
+
flattenedArray.push(keyDirectiveNode);
|
|
1818
|
+
normalizedDirectiveNodes.push(keyDirectiveNode);
|
|
1819
|
+
}
|
|
1820
|
+
directivesByDirectiveName.set(directiveName, normalizedDirectiveNodes);
|
|
1821
|
+
}
|
|
1822
|
+
return flattenedArray;
|
|
1823
|
+
}
|
|
1824
|
+
getEnumNodeByData(enumDefinitionData) {
|
|
1825
|
+
enumDefinitionData.node.description = enumDefinitionData.description;
|
|
1826
|
+
enumDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(enumDefinitionData.directivesByDirectiveName, enumDefinitionData.name);
|
|
1827
|
+
enumDefinitionData.node.values = (0, utils_4.childMapToValueArray)(enumDefinitionData.enumValueDataByValueName, this.authorizationDataByParentTypeName);
|
|
1828
|
+
return enumDefinitionData.node;
|
|
1829
|
+
}
|
|
1830
|
+
getInputObjectNodeByData(inputObjectDefinitionData) {
|
|
1831
|
+
inputObjectDefinitionData.node.description = inputObjectDefinitionData.description;
|
|
1832
|
+
inputObjectDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(inputObjectDefinitionData.directivesByDirectiveName, inputObjectDefinitionData.name);
|
|
1833
|
+
inputObjectDefinitionData.node.fields = (0, utils_4.childMapToValueArray)(inputObjectDefinitionData.inputValueDataByValueName, this.authorizationDataByParentTypeName);
|
|
1834
|
+
return inputObjectDefinitionData.node;
|
|
1835
|
+
}
|
|
1836
|
+
getCompositeOutputNodeByData(compositeOutputData) {
|
|
1837
|
+
compositeOutputData.node.description = compositeOutputData.description;
|
|
1838
|
+
compositeOutputData.node.directives = this.getValidFlattenedDirectiveArray(compositeOutputData.directivesByDirectiveName, compositeOutputData.name);
|
|
1839
|
+
compositeOutputData.node.fields = (0, utils_4.childMapToValueArray)(compositeOutputData.fieldDataByFieldName, this.authorizationDataByParentTypeName);
|
|
1840
|
+
compositeOutputData.node.interfaces = (0, utils_1.setToNamedTypeNodeArray)(compositeOutputData.implementedInterfaceTypeNames);
|
|
1841
|
+
return compositeOutputData.node;
|
|
1842
|
+
}
|
|
1843
|
+
getScalarNodeByData(scalarDefinitionData) {
|
|
1844
|
+
scalarDefinitionData.node.description = scalarDefinitionData.description;
|
|
1845
|
+
scalarDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(scalarDefinitionData.directivesByDirectiveName, scalarDefinitionData.name);
|
|
1846
|
+
return scalarDefinitionData.node;
|
|
1847
|
+
}
|
|
1848
|
+
getSchemaNodeByData(schemaData) {
|
|
1849
|
+
return {
|
|
1850
|
+
description: schemaData.description,
|
|
1851
|
+
directives: this.getValidFlattenedDirectiveArray(schemaData.directivesByDirectiveName, schemaData.name),
|
|
1852
|
+
kind: schemaData.kind,
|
|
1853
|
+
operationTypes: (0, utils_3.mapToArrayOfValues)(schemaData.operationTypes),
|
|
1854
|
+
};
|
|
1855
|
+
}
|
|
1856
|
+
getUnionNodeByData(unionDefinitionData) {
|
|
1857
|
+
unionDefinitionData.node.description = unionDefinitionData.description;
|
|
1858
|
+
unionDefinitionData.node.directives = this.getValidFlattenedDirectiveArray(unionDefinitionData.directivesByDirectiveName, unionDefinitionData.name);
|
|
1859
|
+
unionDefinitionData.node.types = (0, utils_3.mapToArrayOfValues)(unionDefinitionData.memberByMemberTypeName);
|
|
1860
|
+
return unionDefinitionData.node;
|
|
1861
|
+
}
|
|
1330
1862
|
normalize(document) {
|
|
1331
1863
|
/* factory.allDirectiveDefinitions is initialized with v1 directive definitions, and v2 definitions are only added
|
|
1332
1864
|
after the visitor has visited the entire schema and the subgraph is known to be a V2 graph. Consequently,
|
|
@@ -1334,6 +1866,10 @@ class NormalizationFactory {
|
|
|
1334
1866
|
// Collect any renamed root types
|
|
1335
1867
|
(0, walkers_1.upsertDirectiveSchemaAndEntityDefinitions)(this, document);
|
|
1336
1868
|
(0, walkers_1.upsertParentsAndChildren)(this, document);
|
|
1869
|
+
this.validateDirectives(this.schemaData, string_constants_1.SCHEMA);
|
|
1870
|
+
for (const [parentTypeName, parentData] of this.parentDefinitionDataByTypeName) {
|
|
1871
|
+
this.validateDirectives(parentData, parentTypeName);
|
|
1872
|
+
}
|
|
1337
1873
|
(0, walkers_1.consolidateAuthorizationDirectives)(this, document);
|
|
1338
1874
|
for (const interfaceTypeName of this.interfaceTypeNamesWithAuthorizationDirectives) {
|
|
1339
1875
|
const interfaceAuthorizationData = this.authorizationDataByParentTypeName.get(interfaceTypeName);
|
|
@@ -1388,17 +1924,31 @@ class NormalizationFactory {
|
|
|
1388
1924
|
}
|
|
1389
1925
|
// subscriptionFilter is temporarily valid only in an EDG
|
|
1390
1926
|
if (this.edfsDirectiveReferences.size > 0 && this.referencedDirectiveNames.has(string_constants_1.SUBSCRIPTION_FILTER)) {
|
|
1391
|
-
this.directiveDefinitionByDirectiveName.set(string_constants_1.SUBSCRIPTION_FILTER, constants_1.SUBSCRIPTION_FILTER_DEFINITION);
|
|
1392
1927
|
definitions.push(constants_1.SUBSCRIPTION_FILTER_DEFINITION);
|
|
1393
1928
|
definitions.push(constants_1.SUBSCRIPTION_FILTER_CONDITION_DEFINITION);
|
|
1394
1929
|
definitions.push(constants_1.SUBSCRIPTION_FIELD_CONDITION_DEFINITION);
|
|
1395
1930
|
definitions.push(constants_1.SUBSCRIPTION_FILTER_VALUE_DEFINITION);
|
|
1396
1931
|
}
|
|
1932
|
+
if (this.referencedDirectiveNames.has(string_constants_1.CONFIGURE_DESCRIPTION)) {
|
|
1933
|
+
definitions.push(constants_1.CONFIGURE_DESCRIPTION_DEFINITION);
|
|
1934
|
+
}
|
|
1935
|
+
if (this.referencedDirectiveNames.has(string_constants_1.CONFIGURE_CHILD_DESCRIPTIONS)) {
|
|
1936
|
+
definitions.push(constants_1.CONFIGURE_CHILD_DESCRIPTIONS_DEFINITION);
|
|
1937
|
+
}
|
|
1397
1938
|
for (const directiveDefinition of this.customDirectiveDefinitions.values()) {
|
|
1398
1939
|
definitions.push(directiveDefinition);
|
|
1399
1940
|
}
|
|
1400
|
-
if (this.
|
|
1401
|
-
definitions.push(
|
|
1941
|
+
if (this.schemaData.operationTypes.size > 0) {
|
|
1942
|
+
definitions.push(this.getSchemaNodeByData(this.schemaData));
|
|
1943
|
+
}
|
|
1944
|
+
/*
|
|
1945
|
+
* Sometimes an @openfed__configureDescription directive is defined before a description is, e.g., on an extension.
|
|
1946
|
+
* If at this stage there is still no description, it is propagated as an error.
|
|
1947
|
+
* */
|
|
1948
|
+
for (const data of this.invalidConfigureDescriptionNodeDatas) {
|
|
1949
|
+
if (!data.description) {
|
|
1950
|
+
this.errors.push((0, errors_1.configureDescriptionNoDescriptionError)((0, utils_3.kindToTypeString)(data.kind), data.name));
|
|
1951
|
+
}
|
|
1402
1952
|
}
|
|
1403
1953
|
for (const [parentTypeName, parentDefinitionData] of this.parentDefinitionDataByTypeName) {
|
|
1404
1954
|
switch (parentDefinitionData.kind) {
|
|
@@ -1407,14 +1957,15 @@ class NormalizationFactory {
|
|
|
1407
1957
|
this.errors.push((0, errors_1.noDefinedEnumValuesError)(parentTypeName));
|
|
1408
1958
|
break;
|
|
1409
1959
|
}
|
|
1410
|
-
|
|
1960
|
+
(0, utils_4.removeIgnoredDirectives)(parentDefinitionData);
|
|
1961
|
+
definitions.push(this.getEnumNodeByData(parentDefinitionData));
|
|
1411
1962
|
break;
|
|
1412
1963
|
case graphql_1.Kind.INPUT_OBJECT_TYPE_DEFINITION:
|
|
1413
1964
|
if (parentDefinitionData.inputValueDataByValueName.size < 1) {
|
|
1414
1965
|
this.errors.push((0, errors_1.noInputValueDefinitionsError)(parentTypeName));
|
|
1415
1966
|
break;
|
|
1416
1967
|
}
|
|
1417
|
-
definitions.push(
|
|
1968
|
+
definitions.push(this.getInputObjectNodeByData(parentDefinitionData));
|
|
1418
1969
|
break;
|
|
1419
1970
|
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
1420
1971
|
// intentional fallthrough
|
|
@@ -1426,6 +1977,8 @@ class NormalizationFactory {
|
|
|
1426
1977
|
parentDefinitionData.fieldDataByFieldName.delete(string_constants_1.SERVICE_FIELD);
|
|
1427
1978
|
parentDefinitionData.fieldDataByFieldName.delete(string_constants_1.ENTITIES_FIELD);
|
|
1428
1979
|
}
|
|
1980
|
+
(0, utils_4.removeIgnoredDirectives)(parentDefinitionData);
|
|
1981
|
+
(0, utils_4.removeInheritableDirectivesFromObjectParent)(parentDefinitionData);
|
|
1429
1982
|
if (this.parentsWithChildArguments.has(parentTypeName) || !isObject) {
|
|
1430
1983
|
const externalInterfaceFieldNames = [];
|
|
1431
1984
|
for (const [fieldName, fieldData] of parentDefinitionData.fieldDataByFieldName) {
|
|
@@ -1464,7 +2017,7 @@ class NormalizationFactory {
|
|
|
1464
2017
|
this.configurationDataByParentTypeName.set(newParentTypeName, configurationData);
|
|
1465
2018
|
(0, utils_2.addFieldNamesToConfigurationData)(parentDefinitionData.fieldDataByFieldName, configurationData);
|
|
1466
2019
|
this.validateInterfaceImplementations(parentDefinitionData);
|
|
1467
|
-
definitions.push(
|
|
2020
|
+
definitions.push(this.getCompositeOutputNodeByData(parentDefinitionData));
|
|
1468
2021
|
// interfaces and objects must define at least one field
|
|
1469
2022
|
if (parentDefinitionData.fieldDataByFieldName.size < 1 && !(0, utils_2.isNodeQuery)(parentTypeName, operationTypeNode)) {
|
|
1470
2023
|
this.errors.push((0, errors_1.noFieldDefinitionsError)((0, utils_3.kindToTypeString)(parentDefinitionData.kind), parentTypeName));
|
|
@@ -1475,10 +2028,11 @@ class NormalizationFactory {
|
|
|
1475
2028
|
this.errors.push((0, errors_1.noBaseScalarDefinitionError)(parentTypeName));
|
|
1476
2029
|
break;
|
|
1477
2030
|
}
|
|
1478
|
-
|
|
2031
|
+
(0, utils_4.removeIgnoredDirectives)(parentDefinitionData);
|
|
2032
|
+
definitions.push(this.getScalarNodeByData(parentDefinitionData));
|
|
1479
2033
|
break;
|
|
1480
2034
|
case graphql_1.Kind.UNION_TYPE_DEFINITION:
|
|
1481
|
-
definitions.push(
|
|
2035
|
+
definitions.push(this.getUnionNodeByData(parentDefinitionData));
|
|
1482
2036
|
this.validateUnionMembers(parentDefinitionData);
|
|
1483
2037
|
break;
|
|
1484
2038
|
default:
|
|
@@ -1487,7 +2041,7 @@ class NormalizationFactory {
|
|
|
1487
2041
|
}
|
|
1488
2042
|
// Check that explicitly defined operations types are valid objects and that their fields are also valid
|
|
1489
2043
|
for (const operationType of Object.values(graphql_1.OperationTypeNode)) {
|
|
1490
|
-
const operationTypeNode = this.
|
|
2044
|
+
const operationTypeNode = this.schemaData.operationTypes.get(operationType);
|
|
1491
2045
|
const defaultTypeName = (0, utils_3.getOrThrowError)(utils_1.operationTypeNodeToDefaultType, operationType, string_constants_1.OPERATION_TO_DEFAULT);
|
|
1492
2046
|
// If an operation type name was not declared, use the default
|
|
1493
2047
|
const operationTypeName = operationTypeNode ? (0, ast_1.getTypeNodeNamedTypeName)(operationTypeNode.type) : defaultTypeName;
|
|
@@ -1562,7 +2116,7 @@ class NormalizationFactory {
|
|
|
1562
2116
|
if (executableLocations.size < 1) {
|
|
1563
2117
|
continue;
|
|
1564
2118
|
}
|
|
1565
|
-
|
|
2119
|
+
this.addPersistedDirectiveDefinitionDataByNode(persistedDirectiveDefinitionDataByDirectiveName, directiveDefinitionNode, executableLocations);
|
|
1566
2120
|
}
|
|
1567
2121
|
this.isSubgraphEventDrivenGraph = this.edfsDirectiveReferences.size > 0;
|
|
1568
2122
|
if (this.isSubgraphEventDrivenGraph) {
|