Cookbook · Writing
Pass parent_id and you get both a node and the parent edge back in one call. Destructure the wrapped return shape.
Recipe
import { UPGClient } from '@unified-product-graph/sdk'
const upg = new UPGClient({ file: './product.upg' })
// 1. Create the parent.
const { node: persona } = await upg.nodes.create({
type: 'persona',
title: 'Busy Parent',
})
// 2. Create a child + auto-parent edge in one shot.
const { node: job, edge } = await upg.nodes.create({
type: 'job',
title: 'Find ten minutes to work out',
parent_id: persona.id,
})
console.log('node id:', job.id)
console.log('auto edge:', edge?.type, '→', edge?.id)What it does
nodes.create() returns { node, edge? }, not the node directly. Destructure. The edge is present only when parent_id was provided; it is the canonical hierarchy edge for that source-target pair (here: persona_has_job).
Variations
Create without a parent
const { node } = await upg.nodes.create({ type: 'feature', title: 'Dark mode' })Batch create with parallel awaits
const created = await Promise.all(
items.map(i => upg.nodes.create(i)),
)
const nodes = created.map(c => c.node)See also