Inspecting your app
Your composition spans many files. .graph() returns it as a JSON tree — log it, render it as a diagram, feed it to an LLM. Or snapshot it to catch unintended changes.
Inspecting
Section titled “Inspecting”Call .graph() to get the tree without executing Tasks.
Output:
{ "type": "seq", "meta": {}, "children": [ { "type": "run", "meta": { "name": "alpha", "kind": "task" }, "id": 0, "dependencies": { "required": [], "optional": [] } } ]}import {createWire, compose, tag, createTask, optional} from "@grlt-hub/app-compose"
const title = tag<string>("title")
const alpha = createTask({ name: "alpha", run: { fn: () => ({ list: [0], title: "hello" }) },})
const beta = createTask({ name: "beta", run: { context: { title: title.value }, fn: console.log, },})
const gamma = createTask({ name: "gamma", run: { context: { list: optional(alpha.result.list) }, fn: console.log, },})
const app = compose() .step(alpha) .step([ compose() .step(createWire({ from: alpha.result.title, to: title })) .step(beta), gamma, ])
const graph = app.graph()
console.log(JSON.stringify(graph, null, 2))Snapshotting the graph
Section titled “Snapshotting the graph”Snapshot .graph() in a test to catch unintended changes.
import { describe, expect, it } from "vitest"import { app } from "./app"
describe("app graph", () => { it("matches snapshot", () => { expect(app.graph()).toMatchSnapshot() })})