diff --git a/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts b/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts
index 6b1c2d85ee701..798cc207f0aeb 100644
--- a/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts
+++ b/packages/@aws-cdk/pipelines/lib/helpers-internal/graph.ts
@@ -35,7 +35,7 @@ export class GraphNode {
*/
public get allDeps(): GraphNode[] {
const fromParent = this.parentGraph?.allDeps ?? [];
- return [...this.dependencies, ...fromParent];
+ return Array.from(new Set([...this.dependencies, ...fromParent]));
}
public dependOn(...dependencies: Array | undefined>) {
@@ -382,4 +382,4 @@ function projectDependencies(dependencies: Map, Set
export function isGraph(x: GraphNode): x is Graph {
return x instanceof Graph;
-}
\ No newline at end of file
+}
diff --git a/packages/@aws-cdk/pipelines/test/blueprint/helpers-internal/dependencies.test.ts b/packages/@aws-cdk/pipelines/test/blueprint/helpers-internal/dependencies.test.ts
index f577ffae4f80c..9610472554301 100644
--- a/packages/@aws-cdk/pipelines/test/blueprint/helpers-internal/dependencies.test.ts
+++ b/packages/@aws-cdk/pipelines/test/blueprint/helpers-internal/dependencies.test.ts
@@ -50,3 +50,22 @@ describe('with nested graphs', () => {
]);
});
});
+
+test('duplicate dependencies are ignored', () => {
+ mkGraph('G', G => {
+ const A = G.graph('A', [], GA => {
+ GA.node('aa');
+ });
+
+ // parent graph depnds on A also
+ const B = G.graph('B', [A], GB => {
+ // duplicate dependency on A
+ GB.graph('BB', [A], GBB => {
+ GBB.node('bbb');
+ });
+ GB.node('bb');
+ });
+
+ expect(nodeNames(B.tryGetChild('BB')!.allDeps)).toStrictEqual(['A']);
+ });
+});