Skip to content

gi-nx


gi-nx / addFlow

ts
function addFlow(flow: {
  dependencies: GiraffeNodeGraphFeatureDependancy[];
  description?: string;
  edges: GiraffeEdge[];
  id: string;
  inputs: Record<string, GiraffeNodeInputHandle>;
  name: string;
  nodes: GiraffeNode[];
  outputs: Record<string, GiraffeNodeInputHandle>;
  supportedShapes?: string[];
}): void;

Adds a flow to the project.

A flow is a node graph where each node has a type which is the GUID of a node definition. See all available node types at: https://gi-docs-beta.web.app/md/nodes.md

Parameters

ParameterTypeDescription
flow.dependenciesGiraffeNodeGraphFeatureDependancy[]-
flow.description?string-
flow.edgesGiraffeEdge[]-
flow.idstring-
flow.inputsRecord<string, GiraffeNodeInputHandle>-
flow.namestring-
flow.nodesGiraffeNode[]-
flow.outputsRecord<string, GiraffeNodeInputHandle>-
flow.supportedShapes?string[]-

Returns

void

Example

typescript
const id = nanoid();
const entryId = nanoid();
const exitId = nanoid();
const makeEdgeId = (source: string, sourceHandle: string, target: string, targetHandle: string) =>
  `reactflow__edge-${source}${sourceHandle}-${target}${targetHandle}`;

// Node type GUIDs — see https://gi-docs-beta.web.app/md/nodes.md for all available nodes
const READ_FEATURE  = '1a4c8f02-f831-4bdd-b2f8-c9b647b10266';
const WRITE_FEATURE = 'ed22a41d-e114-4734-876f-2362d02fc5ce';

gi.addFlow({
  id,
  name: "Identity",
  nodes: [
    {
      id: entryId,
      type: READ_FEATURE,
      position: { x: 132, y: 0 },
      data: {}
    },
    {
      id: exitId,
      type: WRITE_FEATURE,
      position: { x: 353, y: 0 },
      data: {}
    }
  ],
  edges: [
    {
      source: entryId,
      sourceHandle: "feature",
      target: exitId,
      targetHandle: "feature",
      id: makeEdgeId(entryId, "feature", exitId, "feature"),
      type: "giraffeNodesEdge"
    }
  ],
  inputs: {},
  outputs: {},
  dependencies: []
});