Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(graph): add edge to map relationship between declarations and decorators on fields #148

Merged
merged 11 commits into from
Nov 1, 2024
2 changes: 2 additions & 0 deletions lib/common/diagramvisitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,8 @@ class DiagramVisitor {
*/
visitMapDeclaration(mapDeclaration, parameters) {
mapDeclaration.getDecorators().forEach(decorator => decorator.accept(this, parameters));
mapDeclaration.getKey().getDecorators().forEach(decorator => decorator.accept(this, parameters));
mapDeclaration.getValue().getDecorators().forEach(decorator => decorator.accept(this, parameters));
return;
}

Expand Down
30 changes: 21 additions & 9 deletions lib/common/graph.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,15 +215,27 @@ class ConcertoGraphVisitor extends DiagramVisitor {
super.visitDecorator(decorator, parameters);
const parent = decorator.getParent();
const modelFile = parent.getModelFile();
decorator.getArguments()?.forEach(argument => {
if(argument && argument.name) {
const fqn = modelFile.getFullyQualifiedTypeName(argument.name);
if (fqn) {
parameters.graph.addVertex(fqn);
muhabdulkadir marked this conversation as resolved.
Show resolved Hide resolved
(parent === modelFile) ? parameters.graph.addEdge(parent.getNamespace(), fqn) : parameters.graph.addEdge(parent.getFullyQualifiedName(), fqn);
}
}
});
// Process the decorator name and arguments in a unified way
const namesToProcess = [
decorator.name,
...(decorator.getArguments()?.map(arg => arg?.name).filter(Boolean) || [])
];
namesToProcess.forEach(name => this.addEdgeForDecorator(name, parent, modelFile, parameters));
}

addEdgeForDecorator(name, parent, modelFile, parameters) {
const fqn = modelFile.getFullyQualifiedTypeName(name);
if (fqn) {
parameters.graph.addVertex(fqn);

// Determine parent FQN based on property type
const type = modelFile.getModelManager().getType(fqn);
const isParentPropertyType = parent.isField?.() || parent.isRelationship?.() || parent.isEnumValue?.() || parent.isKey?.() || parent.isValue?.();
let parentFqn = isParentPropertyType ? parent.getParent().getFullyQualifiedName() : parent.getFullyQualifiedName?.();
parentFqn ??= parent.getNamespace(); //parent is a modelfile

parameters.graph.addEdge(parentFqn, type.getFullyQualifiedName());
}
}

/**
Expand Down
Loading
Loading