From bf4016b4bc062b8fb9635b1726e3405bdd914bf4 Mon Sep 17 00:00:00 2001 From: psychedelicious <4822129+psychedelicious@users.noreply.github.com> Date: Sun, 29 Jun 2025 12:02:31 +1000 Subject: [PATCH] feat(ui): add getNodes method to Graph --- .../nodes/util/graph/generation/Graph.test.ts | 15 +++++++++++++++ .../features/nodes/util/graph/generation/Graph.ts | 8 ++++++++ 2 files changed, 23 insertions(+) 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.