in composition/src/v1/normalization/normalization-factory.ts [2781:2874]
validateEventDrivenSubgraph(definitions: Array<DefinitionNode>) {
const errorMessages: string[] = [];
const invalidEventsDirectiveDataByRootFieldPath = new Map<string, InvalidRootTypeFieldEventsDirectiveData>();
const invalidResponseTypeStringByRootFieldPath = new Map<string, string>();
const invalidResponseTypeNameByMutationPath = new Map<string, string>();
const invalidKeyFieldSetsByEntityTypeName = new Map<string, string[]>();
const nonExternalKeyFieldNameByFieldPath = new Map<string, string>();
const nonKeyFieldNameByFieldPath = new Map<string, string>();
const nonEntityExtensionTypeNames = new Set<string>();
const invalidObjectTypeNames = new Set<string>();
for (const [typeName, data] of this.parentDefinitionDataByTypeName) {
// validate edfs__PublishResult and edfs__NatsStreamConfiguration separately
if (typeName === EDFS_PUBLISH_RESULT || typeName === EDFS_NATS_STREAM_CONFIGURATION) {
continue;
}
if (data.kind !== Kind.OBJECT_TYPE_DEFINITION) {
continue;
}
if (data.isRootType) {
this.validateEventDrivenRootType(
data,
invalidEventsDirectiveDataByRootFieldPath,
invalidResponseTypeStringByRootFieldPath,
invalidResponseTypeNameByMutationPath,
);
continue;
}
const keyFieldNames = this.keyFieldNamesByParentTypeName.get(typeName);
if (!keyFieldNames) {
invalidObjectTypeNames.add(typeName);
continue;
}
this.validateEventDrivenKeyDefinition(typeName, invalidKeyFieldSetsByEntityTypeName);
this.validateEventDrivenObjectFields(
data.fieldDataByFieldName,
keyFieldNames,
nonExternalKeyFieldNameByFieldPath,
nonKeyFieldNameByFieldPath,
);
}
if (!this.isEdfsPublishResultValid()) {
errorMessages.push(invalidEdfsPublishResultObjectErrorMessage);
}
if (this.edfsDirectiveReferences.has(EDFS_NATS_SUBSCRIBE)) {
const streamConfigurationInputData = this.parentDefinitionDataByTypeName.get(EDFS_NATS_STREAM_CONFIGURATION);
if (
streamConfigurationInputData &&
this.usesEdfsNatsStreamConfiguration &&
!this.isNatsStreamConfigurationInputObjectValid(streamConfigurationInputData)
) {
errorMessages.push(invalidNatsStreamConfigurationDefinitionErrorMessage);
}
// always add the correct definition to the schema regardless
this.parentDefinitionDataByTypeName.delete(EDFS_NATS_STREAM_CONFIGURATION);
definitions.push(EDFS_NATS_STREAM_CONFIGURATION_DEFINITION);
}
if (this.referencedDirectiveNames.has(LINK)) {
definitions.push(LINK_DEFINITION);
definitions.push(LINK_IMPORT_DEFINITION);
definitions.push(LINK_PURPOSE_DEFINITION);
}
if (invalidEventsDirectiveDataByRootFieldPath.size > 0) {
errorMessages.push(invalidRootTypeFieldEventsDirectivesErrorMessage(invalidEventsDirectiveDataByRootFieldPath));
}
if (invalidResponseTypeNameByMutationPath.size > 0) {
errorMessages.push(invalidEventDrivenMutationResponseTypeErrorMessage(invalidResponseTypeNameByMutationPath));
}
if (invalidResponseTypeStringByRootFieldPath.size > 0) {
errorMessages.push(
invalidRootTypeFieldResponseTypesEventDrivenErrorMessage(invalidResponseTypeStringByRootFieldPath),
);
}
if (invalidKeyFieldSetsByEntityTypeName.size > 0) {
errorMessages.push(invalidKeyFieldSetsEventDrivenErrorMessage(invalidKeyFieldSetsByEntityTypeName));
}
if (nonExternalKeyFieldNameByFieldPath.size > 0) {
errorMessages.push(nonExternalKeyFieldNamesEventDrivenErrorMessage(nonExternalKeyFieldNameByFieldPath));
}
if (nonKeyFieldNameByFieldPath.size > 0) {
errorMessages.push(nonKeyFieldNamesEventDrivenErrorMessage(nonKeyFieldNameByFieldPath));
}
if (nonEntityExtensionTypeNames.size > 0) {
errorMessages.push(nonEntityObjectExtensionsEventDrivenErrorMessage([...nonEntityExtensionTypeNames]));
}
if (invalidObjectTypeNames.size > 0) {
errorMessages.push(nonKeyComposingObjectTypeNamesEventDrivenErrorMessage([...invalidObjectTypeNames]));
}
if (errorMessages.length > 0) {
this.errors.push(invalidEventDrivenGraphError(errorMessages));
}
}