diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts index cade0e1a3e..60c5ab44b5 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.test.ts @@ -138,6 +138,21 @@ describe('Graph', () => { }); }); + describe('getNodes', () => { + it('should return all nodes in the graph', () => { + const g = new Graph(); + const n1 = g.addNode({ + id: 'n1', + type: 'add', + }); + const n2 = g.addNode({ + id: 'n2', + type: 'sub', + }); + expect(g.getNodes()).toEqual([n1, n2]); + }); + }); + describe('addEdge', () => { const add: Invocation<'add'> = { id: 'from-node', diff --git a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts index b096996e38..081e2c4370 100644 --- a/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts +++ b/invokeai/frontend/web/src/features/nodes/util/graph/generation/Graph.ts @@ -128,6 +128,14 @@ export class Graph { return node; } + /** + * Gets all nodes in the graph. + * @returns An array of all nodes in the graph. + */ + getNodes(): AnyInvocation[] { + return Object.values(this._graph.nodes); + } + /** * Get the immediate incomers of a node. * @param node The node to get the incomers of.