flows
The flows namespace is a registry for host-injected schema callbacks consumed by engine-side interaction flows.
The engine itself is schema-agnostic — it does not know what categories exist in your dataset, what relationship types are valid, or how the user should be prompted to pick them. The host (e.g. the Kineviz platform) registers async resolver callbacks at mount time, and engine flow primitives (CreateNodeFlow, CreateEdgeFlow, ChangeCategoryFlow, …) invoke them when the user runs an action that needs schema input.
Registering schema callbacks
api.flows.setSchemaCallbacks({
async onResolveCategoriesForNewNode() {
return [
{ id: "Person", name: "Person", color: "#4af" },
{ id: "Company", name: "Company", color: "#fa4" },
{ id: "Location", name: "Location", color: "#4fa" },
];
},
async onResolveRelationshipTypesForNewEdge(sourceId, targetId) {
const valid = await myBackend.allowedRelations(sourceId, targetId);
return valid.map(r => ({ id: r, name: r, direction: "outgoing" }));
},
async onResolveCategoriesForChange(nodeId) {
return everyCategoryExceptCurrent(nodeId);
},
});
The callbacks return resolved data; the engine renders the prompt UI and applies the chosen value.
Conditional menu visibility
hasCallback(name) lets engine code check whether a given callback is registered before showing a related menu item:
// Inside an engine menu builder
if (api.flows.hasCallback("onResolveCategoriesForNewNode")) {
menu.add({ id: "create-node", label: "Create node…" });
}
If the host hasn't registered the callback, the menu item is omitted — the engine never offers an action it can't fulfil.
Why this lives in the API
The engine treats flows as a one-way "host → engine" channel for schema metadata. There are no reads to perform, no state to query — just a registration site that engine internals consult on demand. Keep your callback registration adjacent to where you mount <GraphCanvas>:
useEffect(() => {
if (!apiRef.current) return;
apiRef.current.flows.setSchemaCallbacks(buildSchemaCallbacks(myBackend));
}, [apiRef]);