Cookbook · Reading
Follow typed edges to assemble a multi-hop view in a few lines.
Recipe
import { UPGClient } from '@unified-product-graph/sdk'
const upg = new UPGClient({ file: './product.upg' })
const { nodes: personas } = await upg.nodes.list({ type: 'persona' })
for (const persona of personas) {
const pursues = await upg.edges.list({
source: persona.id,
type: 'persona_pursues_job',
})
for (const edge of pursues) {
const job = await upg.nodes.get(edge.target)
const features = await upg.edges.list({
target: edge.target,
type: 'feature_addresses_job',
})
console.log(
`${persona.title} → ${job?.title} (${features.length} features)`,
)
}
}What it does
edges.list() returns an array (unlike nodes.list which wraps). Filter by source / target / type; combine all three for a tight query. nodes.get() returns the node or undefined, so guard with ?. or throw on null where you need a hard contract.
Variations
Walk both directions (incoming + outgoing)
const outgoing = await upg.edges.list({ source: node.id })
const incoming = await upg.edges.list({ target: node.id })Walk by edge type only (no source/target)
await upg.edges.list({ type: 'persona_pursues_job' })See also