fix(orchestration): Infinite loop by reference update (#5023)
* fix(orchestration): Infinite loop by reference update * fix * handle conflict alias config * rm field alias * Create wet-gorillas-laugh.md
This commit is contained in:
@@ -128,15 +128,18 @@ export class RemoteJoiner {
|
||||
}
|
||||
|
||||
private buildReferences(serviceConfigs: ModuleJoinerConfig[]) {
|
||||
const expandedRelationships: Map<string, JoinerRelationship[]> = new Map()
|
||||
const expandedRelationships: Map<
|
||||
string,
|
||||
{ fieldAlias; relationships: JoinerRelationship[] }
|
||||
> = new Map()
|
||||
for (const service of serviceConfigs) {
|
||||
if (this.serviceConfigCache.has(service.serviceName!)) {
|
||||
throw new Error(`Service "${service.serviceName}" is already defined.`)
|
||||
}
|
||||
|
||||
if (!service.relationships) {
|
||||
service.relationships = []
|
||||
}
|
||||
service.fieldAlias ??= {}
|
||||
service.relationships ??= []
|
||||
service.extends ??= []
|
||||
|
||||
// add aliases
|
||||
const isReadOnlyDefinition =
|
||||
@@ -175,26 +178,47 @@ export class RemoteJoiner {
|
||||
this.cacheServiceConfig(serviceConfigs, service.serviceName)
|
||||
}
|
||||
|
||||
if (!service.extends) {
|
||||
continue
|
||||
}
|
||||
|
||||
for (const extend of service.extends) {
|
||||
if (!expandedRelationships.has(extend.serviceName)) {
|
||||
expandedRelationships.set(extend.serviceName, [])
|
||||
expandedRelationships.set(extend.serviceName, {
|
||||
fieldAlias: {},
|
||||
relationships: [],
|
||||
})
|
||||
}
|
||||
|
||||
expandedRelationships.get(extend.serviceName)!.push(extend.relationship)
|
||||
const service_ = expandedRelationships.get(extend.serviceName)!
|
||||
service_.relationships.push(extend.relationship)
|
||||
Object.assign(service_.fieldAlias ?? {}, extend.fieldAlias)
|
||||
}
|
||||
}
|
||||
|
||||
for (const [serviceName, relationships] of expandedRelationships) {
|
||||
for (const [
|
||||
serviceName,
|
||||
{ fieldAlias, relationships },
|
||||
] of expandedRelationships) {
|
||||
if (!this.serviceConfigCache.has(serviceName)) {
|
||||
throw new Error(`Service "${serviceName}" was not found`)
|
||||
}
|
||||
|
||||
const service = this.serviceConfigCache.get(serviceName)
|
||||
service!.relationships?.push(...relationships)
|
||||
const service_ = this.serviceConfigCache.get(serviceName)!
|
||||
service_.relationships?.push(...relationships)
|
||||
Object.assign(service_.fieldAlias!, fieldAlias ?? {})
|
||||
|
||||
if (Object.keys(service_.fieldAlias!).length) {
|
||||
const conflictAliases = service_.relationships!.filter(
|
||||
(relationship) => {
|
||||
return fieldAlias[relationship.alias]
|
||||
}
|
||||
)
|
||||
|
||||
if (conflictAliases.length) {
|
||||
throw new Error(
|
||||
`Conflict configuration for service "${serviceName}". The following aliases are already defined as relationships: ${conflictAliases
|
||||
.map((relationship) => relationship.alias)
|
||||
.join(", ")}`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return serviceConfigs
|
||||
|
||||
Reference in New Issue
Block a user