Cookbook · Writing
Shallow-merge a patch onto an existing node. Persists on every call.
Recipe
import { UPGClient } from '@unified-product-graph/sdk'
const upg = new UPGClient({ file: './product.upg' })
const node = await upg.nodes.get('n_Kg19aubWwbwm7V5t')
if (!node) throw new Error('node not found')
const updated = await upg.nodes.update(node.id, {
status: 'active',
updated_at: new Date().toISOString(),
})
console.log('now:', updated.status, '@', updated.updated_at)What it does
update() is a shallow merge, so pass only the fields you want to change. Unlike create(), update() returns the node directly (not wrapped). The file flushes after the call.
Variations
Update multiple nodes at once
await Promise.all(
ids.map(id => upg.nodes.update(id, { status: 'archived' })),
)Conditional update (read-then-write)
const node = await upg.nodes.get(id)
if (node?.status === 'draft') {
await upg.nodes.update(id, { status: 'active' })
}See also