@wundergraph/composition 0.19.0 → 0.20.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 +1 -1
- package/dist/ast/utils.js.map +1 -1
- package/dist/errors/errors.d.ts +19 -3
- package/dist/errors/errors.js +171 -18
- package/dist/errors/errors.js.map +1 -1
- package/dist/errors/utils.d.ts +4 -0
- package/dist/errors/utils.js +3 -0
- package/dist/errors/utils.js.map +1 -0
- package/dist/federation/federation-factory.d.ts +4 -4
- package/dist/federation/federation-factory.js +15 -15
- package/dist/federation/federation-factory.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/normalization-factory.d.ts +18 -9
- package/dist/normalization/normalization-factory.js +273 -61
- package/dist/normalization/normalization-factory.js.map +1 -1
- package/dist/normalization/utils.d.ts +4 -5
- package/dist/normalization/utils.js +12 -12
- package/dist/normalization/utils.js.map +1 -1
- package/dist/normalization/walkers.js +31 -24
- package/dist/normalization/walkers.js.map +1 -1
- package/dist/router-configuration/router-configuration.d.ts +1 -1
- package/dist/schema-building/ast.d.ts +3 -4
- package/dist/schema-building/ast.js +9 -32
- package/dist/schema-building/ast.js.map +1 -1
- package/dist/schema-building/type-merging.d.ts +2 -2
- package/dist/schema-building/type-merging.js +8 -7
- package/dist/schema-building/type-merging.js.map +1 -1
- package/dist/schema-building/utils.d.ts +1 -1
- package/dist/schema-building/utils.js +21 -15
- package/dist/schema-building/utils.js.map +1 -1
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/utils/constants.js +31 -10
- package/dist/utils/constants.js.map +1 -1
- package/dist/utils/string-constants.d.ts +11 -2
- package/dist/utils/string-constants.js +13 -4
- package/dist/utils/string-constants.js.map +1 -1
- package/dist/utils/utils.d.ts +6 -6
- package/dist/utils/utils.js +16 -16
- package/dist/utils/utils.js.map +1 -1
- package/package.json +3 -3
|
@@ -25,7 +25,7 @@ function normalizeSubgraphFromString(subgraphSDL) {
|
|
|
25
25
|
return normalizationFactory.normalize(documentNode);
|
|
26
26
|
}
|
|
27
27
|
exports.normalizeSubgraphFromString = normalizeSubgraphFromString;
|
|
28
|
-
function normalizeSubgraph(document,
|
|
28
|
+
function normalizeSubgraph(document, subgraphName, graph) {
|
|
29
29
|
const normalizationFactory = new NormalizationFactory(graph || new graphology_1.MultiGraph(), subgraphName);
|
|
30
30
|
return normalizationFactory.normalize(document);
|
|
31
31
|
}
|
|
@@ -39,14 +39,15 @@ class NormalizationFactory {
|
|
|
39
39
|
customDirectiveDefinitions = new Map();
|
|
40
40
|
directiveDefinitionByDirectiveName = new Map();
|
|
41
41
|
errors = [];
|
|
42
|
-
|
|
42
|
+
entityDataByTypeName = new Map();
|
|
43
43
|
entityInterfaces = new Map();
|
|
44
44
|
graph;
|
|
45
45
|
parentExtensionDataByTypeName = new Map();
|
|
46
46
|
interfaceTypeNamesWithAuthorizationDirectives = new Set();
|
|
47
47
|
isCurrentParentExtension = false;
|
|
48
|
+
isEventDrivenSubgraph = false;
|
|
48
49
|
isSubgraphVersionTwo = false;
|
|
49
|
-
|
|
50
|
+
fieldSetDataByTypeName = new Map();
|
|
50
51
|
heirFieldAuthorizationDataByTypeName = new Map();
|
|
51
52
|
handledRepeatedDirectivesByHostPath = new Map();
|
|
52
53
|
lastParentNodeKind = graphql_1.Kind.NULL;
|
|
@@ -301,16 +302,16 @@ class NormalizationFactory {
|
|
|
301
302
|
if (node.kind === graphql_1.Kind.INTERFACE_TYPE_DEFINITION || node.kind === graphql_1.Kind.INTERFACE_TYPE_EXTENSION || !isEntity) {
|
|
302
303
|
return;
|
|
303
304
|
}
|
|
304
|
-
const
|
|
305
|
-
this.extractKeyFieldSets(node,
|
|
306
|
-
(0, utils_3.
|
|
305
|
+
const fieldSetData = (0, utils_3.getValueOrDefault)(this.fieldSetDataByTypeName, this.originalParentTypeName, utils_2.newFieldSetData);
|
|
306
|
+
this.extractKeyFieldSets(node, fieldSetData);
|
|
307
|
+
(0, utils_3.upsertEntityDataProperties)(this.entityDataByTypeName, {
|
|
307
308
|
typeName: this.originalParentTypeName,
|
|
308
|
-
keyFieldSets:
|
|
309
|
+
keyFieldSets: fieldSetData.isUnresolvableByKeyFieldSet.keys(),
|
|
309
310
|
...(this.subgraphName ? { subgraphNames: [this.subgraphName] } : {}),
|
|
310
311
|
});
|
|
311
312
|
}
|
|
312
|
-
extractKeyFieldSets(node,
|
|
313
|
-
const
|
|
313
|
+
extractKeyFieldSets(node, fieldSetData) {
|
|
314
|
+
const isUnresolvableByRawKeyFieldSet = fieldSetData.isUnresolvableByKeyFieldSet;
|
|
314
315
|
const parentTypeName = node.name.value;
|
|
315
316
|
if (!node.directives?.length) {
|
|
316
317
|
// This should never happen
|
|
@@ -326,47 +327,63 @@ class NormalizationFactory {
|
|
|
326
327
|
errorMessages.push((0, errors_1.undefinedRequiredArgumentsErrorMessage)(string_constants_1.KEY, parentTypeName, [string_constants_1.FIELDS]));
|
|
327
328
|
continue;
|
|
328
329
|
}
|
|
330
|
+
let keyFieldSet;
|
|
331
|
+
let isUnresolvable = false;
|
|
329
332
|
for (const arg of directive.arguments) {
|
|
330
|
-
const argumentName = arg.name.value;
|
|
331
333
|
if (arg.name.value === string_constants_1.RESOLVABLE) {
|
|
332
334
|
if (arg.value.kind === graphql_1.Kind.BOOLEAN && !arg.value.value) {
|
|
333
|
-
|
|
335
|
+
isUnresolvable = true;
|
|
334
336
|
}
|
|
335
337
|
continue;
|
|
336
338
|
}
|
|
337
339
|
if (arg.name.value !== string_constants_1.FIELDS) {
|
|
338
|
-
|
|
340
|
+
keyFieldSet = undefined;
|
|
339
341
|
break;
|
|
340
342
|
}
|
|
341
343
|
if (arg.value.kind !== graphql_1.Kind.STRING) {
|
|
344
|
+
keyFieldSet = undefined;
|
|
342
345
|
errorMessages.push((0, errors_1.invalidKeyDirectiveArgumentErrorMessage)(arg.value.kind));
|
|
343
346
|
break;
|
|
344
347
|
}
|
|
345
|
-
|
|
348
|
+
keyFieldSet = arg.value.value;
|
|
349
|
+
}
|
|
350
|
+
if (keyFieldSet !== undefined) {
|
|
351
|
+
isUnresolvableByRawKeyFieldSet.set(keyFieldSet, isUnresolvable);
|
|
346
352
|
}
|
|
347
353
|
}
|
|
348
354
|
if (errorMessages.length) {
|
|
349
355
|
this.errors.push((0, errors_1.invalidKeyDirectivesError)(parentTypeName, errorMessages));
|
|
350
356
|
}
|
|
351
357
|
}
|
|
352
|
-
validateInterfaceImplementations(
|
|
353
|
-
if (
|
|
358
|
+
validateInterfaceImplementations(data) {
|
|
359
|
+
if (data.implementedInterfaceTypeNames.size < 1) {
|
|
354
360
|
return;
|
|
355
361
|
}
|
|
356
362
|
const implementationErrorsMap = new Map();
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
363
|
+
const invalidImplementationTypeStringByTypeName = new Map();
|
|
364
|
+
let doesInterfaceImplementItself = false;
|
|
365
|
+
for (const interfaceName of data.implementedInterfaceTypeNames) {
|
|
366
|
+
const implementationData = this.parentDefinitionDataByTypeName.get(interfaceName);
|
|
367
|
+
if (!implementationData) {
|
|
368
|
+
this.errors.push((0, errors_1.undefinedTypeError)(interfaceName));
|
|
369
|
+
continue;
|
|
370
|
+
}
|
|
371
|
+
if (implementationData.kind !== graphql_1.Kind.INTERFACE_TYPE_DEFINITION) {
|
|
372
|
+
invalidImplementationTypeStringByTypeName.set(implementationData.name, (0, utils_3.kindToTypeString)(implementationData.kind));
|
|
373
|
+
continue;
|
|
374
|
+
}
|
|
375
|
+
if (data.name === implementationData.name) {
|
|
376
|
+
doesInterfaceImplementItself = true;
|
|
377
|
+
continue;
|
|
361
378
|
}
|
|
362
379
|
const implementationErrors = {
|
|
363
380
|
invalidFieldImplementations: new Map(),
|
|
364
381
|
unimplementedFields: [],
|
|
365
382
|
};
|
|
366
383
|
let hasErrors = false;
|
|
367
|
-
for (const [fieldName, interfaceField] of
|
|
384
|
+
for (const [fieldName, interfaceField] of implementationData.fieldDataByFieldName) {
|
|
368
385
|
let hasNestedErrors = false;
|
|
369
|
-
const containerField =
|
|
386
|
+
const containerField = data.fieldDataByFieldName.get(fieldName);
|
|
370
387
|
if (!containerField) {
|
|
371
388
|
hasErrors = true;
|
|
372
389
|
implementationErrors.unimplementedFields.push(fieldName);
|
|
@@ -424,8 +441,14 @@ class NormalizationFactory {
|
|
|
424
441
|
implementationErrorsMap.set(interfaceName, implementationErrors);
|
|
425
442
|
}
|
|
426
443
|
}
|
|
427
|
-
if (
|
|
428
|
-
this.errors.push((0, errors_1.
|
|
444
|
+
if (invalidImplementationTypeStringByTypeName.size > 0) {
|
|
445
|
+
this.errors.push((0, errors_1.invalidImplementedTypeError)(data.name, invalidImplementationTypeStringByTypeName));
|
|
446
|
+
}
|
|
447
|
+
if (doesInterfaceImplementItself) {
|
|
448
|
+
this.errors.push((0, errors_1.selfImplementationError)(data.name));
|
|
449
|
+
}
|
|
450
|
+
if (implementationErrorsMap.size > 0) {
|
|
451
|
+
this.errors.push((0, errors_1.unimplementedInterfaceFieldsError)(data.name, (0, utils_3.kindToTypeString)(data.kind), implementationErrorsMap));
|
|
429
452
|
}
|
|
430
453
|
}
|
|
431
454
|
handleOverrideDeclaration(node, hostPath, errorMessages) {
|
|
@@ -444,6 +467,7 @@ class NormalizationFactory {
|
|
|
444
467
|
overriddenFieldNamesForParent.add(this.childName);
|
|
445
468
|
}
|
|
446
469
|
extractEventDirectivesToConfiguration(node) {
|
|
470
|
+
// Validation is handled elsewhere
|
|
447
471
|
if (!node.directives) {
|
|
448
472
|
return;
|
|
449
473
|
}
|
|
@@ -451,63 +475,248 @@ class NormalizationFactory {
|
|
|
451
475
|
let eventType;
|
|
452
476
|
switch (directive.name.value) {
|
|
453
477
|
case string_constants_1.EVENTS_PUBLISH: {
|
|
454
|
-
eventType =
|
|
478
|
+
eventType = string_constants_1.PUBLISH;
|
|
455
479
|
break;
|
|
456
480
|
}
|
|
457
481
|
case string_constants_1.EVENTS_REQUEST: {
|
|
458
|
-
eventType =
|
|
482
|
+
eventType = string_constants_1.REQUEST;
|
|
459
483
|
break;
|
|
460
484
|
}
|
|
461
485
|
case string_constants_1.EVENTS_SUBSCRIBE: {
|
|
462
|
-
eventType =
|
|
486
|
+
eventType = string_constants_1.SUBSCRIBE;
|
|
463
487
|
break;
|
|
464
488
|
}
|
|
465
489
|
default:
|
|
466
490
|
continue;
|
|
467
491
|
}
|
|
468
492
|
let topic;
|
|
469
|
-
let
|
|
470
|
-
for (const
|
|
471
|
-
if (
|
|
472
|
-
|
|
493
|
+
let sourceName;
|
|
494
|
+
for (const argumentNode of directive.arguments || []) {
|
|
495
|
+
if (argumentNode.value.kind !== graphql_1.Kind.STRING) {
|
|
496
|
+
continue;
|
|
473
497
|
}
|
|
474
|
-
switch (
|
|
498
|
+
switch (argumentNode.name.value) {
|
|
475
499
|
case string_constants_1.TOPIC: {
|
|
476
|
-
|
|
477
|
-
throw new Error(`Event directives must have exactly one topic argument, found multiple`);
|
|
478
|
-
}
|
|
479
|
-
if (!arg.value.value) {
|
|
480
|
-
throw new Error(`Event directives must have a non-empty topic argument`);
|
|
481
|
-
}
|
|
482
|
-
topic = arg.value.value;
|
|
500
|
+
topic = argumentNode.value.value;
|
|
483
501
|
break;
|
|
484
502
|
}
|
|
485
|
-
case string_constants_1.
|
|
486
|
-
|
|
487
|
-
throw new Error(`Event directives must have exactly one sourceID argument, found multiple`);
|
|
488
|
-
}
|
|
489
|
-
if (!arg.value.value) {
|
|
490
|
-
throw new Error(`Event directives must have a non-empty sourceID argument`);
|
|
491
|
-
}
|
|
492
|
-
sourceId = arg.value.value;
|
|
503
|
+
case string_constants_1.SOURCE_NAME: {
|
|
504
|
+
sourceName = argumentNode.value.value;
|
|
493
505
|
break;
|
|
494
506
|
}
|
|
495
|
-
default:
|
|
496
|
-
throw new Error(`Unknown argument ${arg.name.value} found in event directive`);
|
|
497
507
|
}
|
|
498
508
|
}
|
|
499
509
|
if (!topic) {
|
|
500
|
-
|
|
510
|
+
return;
|
|
501
511
|
}
|
|
502
512
|
const configuration = (0, utils_3.getValueOrDefault)(this.eventsConfigurations, this.renamedParentTypeName || this.originalParentTypeName, () => []);
|
|
503
513
|
configuration.push({
|
|
504
514
|
type: eventType,
|
|
505
515
|
fieldName: this.childName,
|
|
506
516
|
topic,
|
|
507
|
-
|
|
517
|
+
sourceName: sourceName || string_constants_1.DEFAULT,
|
|
508
518
|
});
|
|
509
519
|
}
|
|
510
520
|
}
|
|
521
|
+
getValidEventsDirectiveNamesForRootTypeName(parentTypeName) {
|
|
522
|
+
const operationTypeNode = this.operationTypeNodeByTypeName.get(parentTypeName);
|
|
523
|
+
if (!operationTypeNode) {
|
|
524
|
+
switch (parentTypeName) {
|
|
525
|
+
case string_constants_1.MUTATION:
|
|
526
|
+
return new Set([string_constants_1.EVENTS_PUBLISH, string_constants_1.EVENTS_REQUEST]);
|
|
527
|
+
case string_constants_1.QUERY:
|
|
528
|
+
return new Set([string_constants_1.EVENTS_REQUEST]);
|
|
529
|
+
case string_constants_1.SUBSCRIPTION:
|
|
530
|
+
return new Set([string_constants_1.EVENTS_SUBSCRIBE]);
|
|
531
|
+
default:
|
|
532
|
+
return;
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
switch (operationTypeNode) {
|
|
536
|
+
case graphql_1.OperationTypeNode.MUTATION:
|
|
537
|
+
return new Set([string_constants_1.EVENTS_REQUEST, string_constants_1.EVENTS_PUBLISH]);
|
|
538
|
+
case graphql_1.OperationTypeNode.QUERY:
|
|
539
|
+
return new Set([string_constants_1.EVENTS_REQUEST]);
|
|
540
|
+
case graphql_1.OperationTypeNode.SUBSCRIPTION:
|
|
541
|
+
return new Set([string_constants_1.EVENTS_SUBSCRIBE]);
|
|
542
|
+
default:
|
|
543
|
+
return;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
validateEventDrivenRootType(data, validEventsDirectiveNames, invalidEventsDirectiveDataByRootFieldPath, invalidResponseTypeStringByRootFieldPath, invalidResponseTypeNameByMutationPath) {
|
|
547
|
+
const isMutation = validEventsDirectiveNames.has(string_constants_1.EVENTS_PUBLISH);
|
|
548
|
+
for (const [fieldName, fieldData] of data.fieldDataByFieldName) {
|
|
549
|
+
const fieldPath = `${fieldData.originalParentTypeName}.${fieldName}`;
|
|
550
|
+
const definedEventsDirectiveNames = new Set();
|
|
551
|
+
for (const eventsDirectiveName of string_constants_1.EVENT_DIRECTIVE_NAMES) {
|
|
552
|
+
if (fieldData.directivesByDirectiveName.has(eventsDirectiveName)) {
|
|
553
|
+
definedEventsDirectiveNames.add(eventsDirectiveName);
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
const invalidEventsDirectiveNames = new Set();
|
|
557
|
+
for (const definedEventsDirectiveName of definedEventsDirectiveNames) {
|
|
558
|
+
if (!validEventsDirectiveNames.has(definedEventsDirectiveName)) {
|
|
559
|
+
invalidEventsDirectiveNames.add(definedEventsDirectiveName);
|
|
560
|
+
}
|
|
561
|
+
}
|
|
562
|
+
if (definedEventsDirectiveNames.size < 1 || invalidEventsDirectiveNames.size > 0) {
|
|
563
|
+
invalidEventsDirectiveDataByRootFieldPath.set(fieldPath, {
|
|
564
|
+
definesDirectives: definedEventsDirectiveNames.size > 0,
|
|
565
|
+
invalidDirectiveNames: [...invalidEventsDirectiveNames],
|
|
566
|
+
});
|
|
567
|
+
}
|
|
568
|
+
if (isMutation) {
|
|
569
|
+
const typeString = (0, merge_1.printTypeNode)(fieldData.type);
|
|
570
|
+
if (typeString !== string_constants_1.NON_NULLABLE_PUBLISH_EVENT_RESULT) {
|
|
571
|
+
invalidResponseTypeNameByMutationPath.set(fieldPath, typeString);
|
|
572
|
+
}
|
|
573
|
+
continue;
|
|
574
|
+
}
|
|
575
|
+
const fieldTypeString = (0, merge_1.printTypeNode)(fieldData.type);
|
|
576
|
+
const expectedTypeString = fieldData.namedTypeName + '!';
|
|
577
|
+
let isValid = false;
|
|
578
|
+
const concreteTypeNames = this.concreteTypeNamesByAbstractTypeName.get(fieldData.namedTypeName) ||
|
|
579
|
+
new Set([fieldData.namedTypeName]);
|
|
580
|
+
for (const concreteTypeName of concreteTypeNames) {
|
|
581
|
+
isValid ||= this.entityDataByTypeName.has(concreteTypeName);
|
|
582
|
+
if (isValid) {
|
|
583
|
+
break;
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
if (!isValid || fieldTypeString !== expectedTypeString) {
|
|
587
|
+
invalidResponseTypeStringByRootFieldPath.set(fieldPath, fieldTypeString);
|
|
588
|
+
}
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
validateEventDrivenKeyDefinition(typeName, invalidKeyFieldSetsByEntityTypeName) {
|
|
592
|
+
const fieldSetData = this.fieldSetDataByTypeName.get(typeName);
|
|
593
|
+
if (!fieldSetData) {
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
for (const [keyFieldSet, isUnresolvable] of fieldSetData.isUnresolvableByKeyFieldSet) {
|
|
597
|
+
if (isUnresolvable) {
|
|
598
|
+
continue;
|
|
599
|
+
}
|
|
600
|
+
(0, utils_3.getValueOrDefault)(invalidKeyFieldSetsByEntityTypeName, typeName, () => []).push(keyFieldSet);
|
|
601
|
+
}
|
|
602
|
+
}
|
|
603
|
+
validateEventDrivenObjectFields(fieldDataByFieldName, keyFieldNames, nonExternalKeyFieldNameByFieldPath, nonKeyFieldNameByFieldPath) {
|
|
604
|
+
for (const [fieldName, fieldData] of fieldDataByFieldName) {
|
|
605
|
+
const fieldPath = `${fieldData.originalParentTypeName}.${fieldName}`;
|
|
606
|
+
if (keyFieldNames.has(fieldName)) {
|
|
607
|
+
if (!fieldData.isExternalBySubgraphName.get(this.subgraphName)) {
|
|
608
|
+
nonExternalKeyFieldNameByFieldPath.set(fieldPath, fieldName);
|
|
609
|
+
}
|
|
610
|
+
continue;
|
|
611
|
+
}
|
|
612
|
+
nonKeyFieldNameByFieldPath.set(fieldPath, fieldName);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
isPublishEventResultValid() {
|
|
616
|
+
const data = this.parentDefinitionDataByTypeName.get(string_constants_1.PUBLISH_EVENT_RESULT);
|
|
617
|
+
if (!data) {
|
|
618
|
+
return true;
|
|
619
|
+
}
|
|
620
|
+
if (data.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
if (data.fieldDataByFieldName.size != 1) {
|
|
624
|
+
return false;
|
|
625
|
+
}
|
|
626
|
+
for (const [fieldName, fieldData] of data.fieldDataByFieldName) {
|
|
627
|
+
if (fieldData.argumentDataByArgumentName.size > 0) {
|
|
628
|
+
return false;
|
|
629
|
+
}
|
|
630
|
+
if (fieldName !== string_constants_1.SUCCESS) {
|
|
631
|
+
return false;
|
|
632
|
+
}
|
|
633
|
+
if ((0, merge_1.printTypeNode)(fieldData.type) !== string_constants_1.NON_NULLABLE_BOOLEAN) {
|
|
634
|
+
return false;
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
return true;
|
|
638
|
+
}
|
|
639
|
+
validateEventDrivenSubgraph() {
|
|
640
|
+
const errorMessages = [];
|
|
641
|
+
const invalidEventsDirectiveDataByRootFieldPath = new Map();
|
|
642
|
+
const invalidResponseTypeStringByRootFieldPath = new Map();
|
|
643
|
+
const invalidResponseTypeNameByMutationPath = new Map();
|
|
644
|
+
const invalidKeyFieldSetsByEntityTypeName = new Map();
|
|
645
|
+
const nonExternalKeyFieldNameByFieldPath = new Map();
|
|
646
|
+
const nonKeyFieldNameByFieldPath = new Map();
|
|
647
|
+
const nonEntityExtensionTypeNames = new Set();
|
|
648
|
+
const invalidObjectTypeNames = new Set();
|
|
649
|
+
for (const [typeName, data] of this.parentExtensionDataByTypeName) {
|
|
650
|
+
if (data.kind !== graphql_1.Kind.OBJECT_TYPE_EXTENSION) {
|
|
651
|
+
continue;
|
|
652
|
+
}
|
|
653
|
+
// If a required events directive is returned, the parent type is a root type
|
|
654
|
+
const validEventsDirectiveNames = this.getValidEventsDirectiveNamesForRootTypeName(data.name);
|
|
655
|
+
if (validEventsDirectiveNames) {
|
|
656
|
+
this.validateEventDrivenRootType(data, validEventsDirectiveNames, invalidEventsDirectiveDataByRootFieldPath, invalidResponseTypeStringByRootFieldPath, invalidResponseTypeNameByMutationPath);
|
|
657
|
+
continue;
|
|
658
|
+
}
|
|
659
|
+
const keyFieldNames = this.keyFieldNamesByParentTypeName.get(typeName);
|
|
660
|
+
if (!keyFieldNames || !data.isEntity) {
|
|
661
|
+
nonEntityExtensionTypeNames.add(typeName);
|
|
662
|
+
continue;
|
|
663
|
+
}
|
|
664
|
+
this.validateEventDrivenKeyDefinition(typeName, invalidKeyFieldSetsByEntityTypeName);
|
|
665
|
+
this.validateEventDrivenObjectFields(data.fieldDataByFieldName, keyFieldNames, nonExternalKeyFieldNameByFieldPath, nonKeyFieldNameByFieldPath);
|
|
666
|
+
}
|
|
667
|
+
for (const [typeName, data] of this.parentDefinitionDataByTypeName) {
|
|
668
|
+
if (data.kind !== graphql_1.Kind.OBJECT_TYPE_DEFINITION) {
|
|
669
|
+
continue;
|
|
670
|
+
}
|
|
671
|
+
// validate PublishEventResult separately
|
|
672
|
+
if (typeName === string_constants_1.PUBLISH_EVENT_RESULT) {
|
|
673
|
+
continue;
|
|
674
|
+
}
|
|
675
|
+
// If a required events directive is returned, the parent type is a root type
|
|
676
|
+
const validEventsDirectiveNames = this.getValidEventsDirectiveNamesForRootTypeName(data.name);
|
|
677
|
+
if (validEventsDirectiveNames) {
|
|
678
|
+
this.validateEventDrivenRootType(data, validEventsDirectiveNames, invalidEventsDirectiveDataByRootFieldPath, invalidResponseTypeStringByRootFieldPath, invalidResponseTypeNameByMutationPath);
|
|
679
|
+
continue;
|
|
680
|
+
}
|
|
681
|
+
const keyFieldNames = this.keyFieldNamesByParentTypeName.get(typeName);
|
|
682
|
+
if (!keyFieldNames) {
|
|
683
|
+
invalidObjectTypeNames.add(typeName);
|
|
684
|
+
continue;
|
|
685
|
+
}
|
|
686
|
+
this.validateEventDrivenKeyDefinition(typeName, invalidKeyFieldSetsByEntityTypeName);
|
|
687
|
+
this.validateEventDrivenObjectFields(data.fieldDataByFieldName, keyFieldNames, nonExternalKeyFieldNameByFieldPath, nonKeyFieldNameByFieldPath);
|
|
688
|
+
}
|
|
689
|
+
if (!this.isPublishEventResultValid()) {
|
|
690
|
+
errorMessages.push(errors_1.invalidPublishEventResultObjectErrorMessage);
|
|
691
|
+
}
|
|
692
|
+
if (invalidEventsDirectiveDataByRootFieldPath.size > 0) {
|
|
693
|
+
errorMessages.push((0, errors_1.invalidRootTypeFieldEventsDirectivesErrorMessage)(invalidEventsDirectiveDataByRootFieldPath));
|
|
694
|
+
}
|
|
695
|
+
if (invalidResponseTypeNameByMutationPath.size > 0) {
|
|
696
|
+
errorMessages.push((0, errors_1.invalidEventsDrivenMutationResponseTypeErrorMessage)(invalidResponseTypeNameByMutationPath));
|
|
697
|
+
}
|
|
698
|
+
if (invalidResponseTypeStringByRootFieldPath.size > 0) {
|
|
699
|
+
errorMessages.push((0, errors_1.invalidRootTypeFieldResponseTypesEventDrivenErrorMessage)(invalidResponseTypeStringByRootFieldPath));
|
|
700
|
+
}
|
|
701
|
+
if (invalidKeyFieldSetsByEntityTypeName.size > 0) {
|
|
702
|
+
errorMessages.push((0, errors_1.invalidKeyFieldSetsEventDrivenErrorMessage)(invalidKeyFieldSetsByEntityTypeName));
|
|
703
|
+
}
|
|
704
|
+
if (nonExternalKeyFieldNameByFieldPath.size > 0) {
|
|
705
|
+
errorMessages.push((0, errors_1.nonExternalKeyFieldNamesEventDrivenErrorMessage)(nonExternalKeyFieldNameByFieldPath));
|
|
706
|
+
}
|
|
707
|
+
if (nonKeyFieldNameByFieldPath.size > 0) {
|
|
708
|
+
errorMessages.push((0, errors_1.nonKeyFieldNamesEventDrivenErrorMessage)(nonKeyFieldNameByFieldPath));
|
|
709
|
+
}
|
|
710
|
+
if (nonEntityExtensionTypeNames.size > 0) {
|
|
711
|
+
errorMessages.push((0, errors_1.nonEntityObjectExtensionsEventDrivenErrorMessage)([...nonEntityExtensionTypeNames]));
|
|
712
|
+
}
|
|
713
|
+
if (invalidObjectTypeNames.size > 0) {
|
|
714
|
+
errorMessages.push((0, errors_1.nonKeyComposingObjectTypeNamesEventDrivenErrorMessage)([...invalidObjectTypeNames]));
|
|
715
|
+
}
|
|
716
|
+
if (errorMessages.length > 0) {
|
|
717
|
+
this.errors.push((0, errors_1.invalidEventDrivenGraphError)(errorMessages));
|
|
718
|
+
}
|
|
719
|
+
}
|
|
511
720
|
normalize(document) {
|
|
512
721
|
/* factory.allDirectiveDefinitions is initialized with v1 directive definitions, and v2 definitions are only added
|
|
513
722
|
after the visitor has visited the entire schema and the subgraph is known to be a V2 graph. Consequently,
|
|
@@ -567,7 +776,7 @@ class NormalizationFactory {
|
|
|
567
776
|
const validParentExtensionOrphansByTypeName = new Map();
|
|
568
777
|
const handledParentTypeNames = new Set();
|
|
569
778
|
for (const [extensionTypeName, parentExtensionData] of this.parentExtensionDataByTypeName) {
|
|
570
|
-
const isEntity = this.
|
|
779
|
+
const isEntity = this.entityDataByTypeName.has(extensionTypeName);
|
|
571
780
|
const newParentTypeName = parentExtensionData.kind === graphql_1.Kind.OBJECT_TYPE_EXTENSION
|
|
572
781
|
? parentExtensionData.renamedTypeName || extensionTypeName
|
|
573
782
|
: extensionTypeName;
|
|
@@ -685,7 +894,7 @@ class NormalizationFactory {
|
|
|
685
894
|
case graphql_1.Kind.INTERFACE_TYPE_DEFINITION:
|
|
686
895
|
// intentional fallthrough
|
|
687
896
|
case graphql_1.Kind.OBJECT_TYPE_DEFINITION:
|
|
688
|
-
const isEntity = this.
|
|
897
|
+
const isEntity = this.entityDataByTypeName.has(parentTypeName);
|
|
689
898
|
const operationTypeNode = this.operationTypeNodeByTypeName.get(parentTypeName);
|
|
690
899
|
if (operationTypeNode) {
|
|
691
900
|
parentDefinitionData.fieldDataByFieldName.delete(string_constants_1.SERVICE_FIELD);
|
|
@@ -795,7 +1004,7 @@ class NormalizationFactory {
|
|
|
795
1004
|
}
|
|
796
1005
|
for (const referencedTypeName of this.referencedTypeNames) {
|
|
797
1006
|
if (this.parentDefinitionDataByTypeName.has(referencedTypeName) ||
|
|
798
|
-
this.
|
|
1007
|
+
this.entityDataByTypeName.has(referencedTypeName)) {
|
|
799
1008
|
continue;
|
|
800
1009
|
}
|
|
801
1010
|
const extension = this.parentExtensionDataByTypeName.get(referencedTypeName);
|
|
@@ -803,7 +1012,7 @@ class NormalizationFactory {
|
|
|
803
1012
|
this.errors.push((0, errors_1.undefinedTypeError)(referencedTypeName));
|
|
804
1013
|
}
|
|
805
1014
|
}
|
|
806
|
-
for (const [parentTypeName,
|
|
1015
|
+
for (const [parentTypeName, fieldSetData] of this.fieldSetDataByTypeName) {
|
|
807
1016
|
const parentData = this.parentDefinitionDataByTypeName.get(parentTypeName) ||
|
|
808
1017
|
this.parentExtensionDataByTypeName.get(parentTypeName);
|
|
809
1018
|
if (!parentData ||
|
|
@@ -815,7 +1024,7 @@ class NormalizationFactory {
|
|
|
815
1024
|
continue;
|
|
816
1025
|
}
|
|
817
1026
|
// this is where keys, provides, and requires are added to the ConfigurationData
|
|
818
|
-
(0, utils_2.validateAndAddDirectivesWithFieldSetToConfigurationData)(this, parentData,
|
|
1027
|
+
(0, utils_2.validateAndAddDirectivesWithFieldSetToConfigurationData)(this, parentData, fieldSetData);
|
|
819
1028
|
}
|
|
820
1029
|
const persistedDirectiveDefinitionDataByDirectiveName = new Map();
|
|
821
1030
|
for (const directiveDefinitionNode of this.directiveDefinitionByDirectiveName.values()) {
|
|
@@ -826,6 +1035,9 @@ class NormalizationFactory {
|
|
|
826
1035
|
}
|
|
827
1036
|
(0, utils_4.addPersistedDirectiveDefinitionDataByNode)(persistedDirectiveDefinitionDataByDirectiveName, directiveDefinitionNode, this.errors, this.directiveDefinitionByDirectiveName, this.handledRepeatedDirectivesByHostPath, executableLocations, this.subgraphName);
|
|
828
1037
|
}
|
|
1038
|
+
if (this.isEventDrivenSubgraph) {
|
|
1039
|
+
this.validateEventDrivenSubgraph();
|
|
1040
|
+
}
|
|
829
1041
|
if (this.errors.length > 0) {
|
|
830
1042
|
return { errors: this.errors };
|
|
831
1043
|
}
|
|
@@ -840,7 +1052,7 @@ class NormalizationFactory {
|
|
|
840
1052
|
// It is an Intermediate configuration object that will be converted to an engine configuration in the router
|
|
841
1053
|
concreteTypeNamesByAbstractTypeName: this.concreteTypeNamesByAbstractTypeName,
|
|
842
1054
|
configurationDataByParentTypeName: this.configurationDataByParentTypeName,
|
|
843
|
-
entityContainerByTypeName: this.
|
|
1055
|
+
entityContainerByTypeName: this.entityDataByTypeName,
|
|
844
1056
|
entityInterfaces: this.entityInterfaces,
|
|
845
1057
|
parentDefinitionDataByTypeName: this.parentDefinitionDataByTypeName,
|
|
846
1058
|
parentExtensionDataByTypeName: validParentExtensionOrphansByTypeName,
|
|
@@ -862,7 +1074,7 @@ exports.NormalizationFactory = NormalizationFactory;
|
|
|
862
1074
|
function batchNormalize(subgraphs) {
|
|
863
1075
|
const authorizationDataByParentTypeName = new Map();
|
|
864
1076
|
const concreteTypeNamesByAbstractTypeName = new Map();
|
|
865
|
-
const
|
|
1077
|
+
const entityDataByTypeName = new Map();
|
|
866
1078
|
const internalSubgraphBySubgraphName = new Map();
|
|
867
1079
|
const allOverridesByTargetSubgraphName = new Map();
|
|
868
1080
|
const overrideSourceSubgraphNamesByFieldPath = new Map();
|
|
@@ -887,7 +1099,7 @@ function batchNormalize(subgraphs) {
|
|
|
887
1099
|
if (!subgraph.name) {
|
|
888
1100
|
invalidNameErrorMessages.push((0, errors_1.invalidSubgraphNameErrorMessage)(i, subgraphName));
|
|
889
1101
|
}
|
|
890
|
-
const { errors, normalizationResult } = normalizeSubgraph(subgraph.definitions,
|
|
1102
|
+
const { errors, normalizationResult } = normalizeSubgraph(subgraph.definitions, subgraph.name, graph);
|
|
891
1103
|
if (errors) {
|
|
892
1104
|
validationErrors.push((0, errors_1.subgraphValidationError)(subgraphName, errors));
|
|
893
1105
|
continue;
|
|
@@ -909,7 +1121,7 @@ function batchNormalize(subgraphs) {
|
|
|
909
1121
|
(0, utils_3.addIterableValuesToSet)(incomingConcreteTypeNames, existingConcreteTypeNames);
|
|
910
1122
|
}
|
|
911
1123
|
for (const entityContainer of normalizationResult.entityContainerByTypeName.values()) {
|
|
912
|
-
(0, utils_3.
|
|
1124
|
+
(0, utils_3.upsertEntityData)(entityDataByTypeName, entityContainer);
|
|
913
1125
|
}
|
|
914
1126
|
if (subgraph.name) {
|
|
915
1127
|
internalSubgraphBySubgraphName.set(subgraphName, {
|
|
@@ -978,7 +1190,7 @@ function batchNormalize(subgraphs) {
|
|
|
978
1190
|
return {
|
|
979
1191
|
authorizationDataByParentTypeName,
|
|
980
1192
|
concreteTypeNamesByAbstractTypeName,
|
|
981
|
-
entityContainerByTypeName,
|
|
1193
|
+
entityContainerByTypeName: entityDataByTypeName,
|
|
982
1194
|
errors: allErrors,
|
|
983
1195
|
graph,
|
|
984
1196
|
internalSubgraphBySubgraphName,
|
|
@@ -1002,7 +1214,7 @@ function batchNormalize(subgraphs) {
|
|
|
1002
1214
|
return {
|
|
1003
1215
|
authorizationDataByParentTypeName,
|
|
1004
1216
|
concreteTypeNamesByAbstractTypeName,
|
|
1005
|
-
entityContainerByTypeName:
|
|
1217
|
+
entityContainerByTypeName: entityDataByTypeName,
|
|
1006
1218
|
graph,
|
|
1007
1219
|
internalSubgraphBySubgraphName: internalSubgraphBySubgraphName,
|
|
1008
1220
|
...(warnings.length > 0 ? { warnings } : {}),
|