SDK · Playground
Pick a recipe, hit Run to see the simulated output, or Open in StackBlitz to get a live Node.js environment with @unified-product-graph/sdk pre-installed and the recipe ready to edit and run.
Cookbook · Maintaining
Wrap a bulk create in a verify-and-rollback pattern so a bad batch never lands on disk.
Code
import { UPGClient, type CreateNodeArgs } from '@unified-product-graph/sdk'
const upg = new UPGClient({ file: './product.upg' })
async function safeBulkCreate(items: CreateNodeArgs[]) {
const before = await upg.health()
const created = await Promise.all(items.map(i => upg.nodes.create(i)))
const report = await upg.verify()
if (report.errors.length > 0) {
console.error('rollback — validation failed:', report.errors)
for (const { node } of created) {
await upg.nodes.delete(node.id)
}
return null
}
const after = await upg.health()
console.log(`+${created.length} nodes · health ${before.score} → ${after.score}`)
return created
}Output
// click ▶ Run to see what this snippet would print locally