diff --git a/packages/core/graph/src/AdjacencyList.js b/packages/core/graph/src/AdjacencyList.js index d68b2463f6a..803655099ab 100644 --- a/packages/core/graph/src/AdjacencyList.js +++ b/packages/core/graph/src/AdjacencyList.js @@ -329,10 +329,18 @@ export default class AdjacencyList { hasEdge( from: NodeId, to: NodeId, - type: TEdgeType | NullEdgeType = 1, + type: TEdgeType | NullEdgeType | Array = 1, ): boolean { - let hash = this.#edges.hash(from, to, type); - return this.#edges.addressOf(hash, from, to, type) !== null; + let hasEdge = (type: TEdgeType | NullEdgeType) => { + let hash = this.#edges.hash(from, to, type); + return this.#edges.addressOf(hash, from, to, type) !== null; + }; + + if (Array.isArray(type)) { + return type.some(hasEdge); + } + + return hasEdge(type); } /** diff --git a/packages/core/graph/src/Graph.js b/packages/core/graph/src/Graph.js index 31faaf3b7a1..ecdd48dc55a 100644 --- a/packages/core/graph/src/Graph.js +++ b/packages/core/graph/src/Graph.js @@ -104,7 +104,7 @@ export default class Graph { hasEdge( from: NodeId, to: NodeId, - type?: TEdgeType | NullEdgeType = 1, + type?: TEdgeType | NullEdgeType | Array = 1, ): boolean { return this.adjacencyList.hasEdge(from, to, type); } diff --git a/packages/core/graph/test/AdjacencyList.test.js b/packages/core/graph/test/AdjacencyList.test.js index 32108771f98..37f096b6fa3 100644 --- a/packages/core/graph/test/AdjacencyList.test.js +++ b/packages/core/graph/test/AdjacencyList.test.js @@ -243,6 +243,21 @@ describe('AdjacencyList', () => { AdjacencyList.prototype.hash = originalHash; }); + it('hasEdge should accept an array of edge types', () => { + let graph = new AdjacencyList(); + let a = graph.addNode(); + let b = graph.addNode(); + let c = graph.addNode(); + + graph.addEdge(a, b, 1); + graph.addEdge(b, c, 2); + + assert.ok(!graph.hasEdge(a, b, [2, 3])); + assert.ok(graph.hasEdge(a, b, [1, 2])); + assert.ok(!graph.hasEdge(b, c, [1, 3])); + assert.ok(graph.hasEdge(b, c, [2, 3])); + }); + describe('deserialize', function () { this.timeout(10000);