Cookbook · Maintaining
Wrap a bulk create in a verify-and-rollback pattern so a bad batch never lands on disk.
Recipe
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.ok) {
console.error('rollback — validation failed:', report.contentValidationErrors)
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
}What it does
verify() returns a VerifyResult: { ok, tampered, quarantined, orphanedEdges, contentValidationErrors }. `ok` is the clean-check; on false, contentValidationErrors holds the per-entity problems (each with a path + message). The pattern: create, verify, roll back when not ok. Cheaper than pre-validating each item because the load-time content validator catches cross-node problems the SDK does not flag at create time.
Variations
Soft-warn mode (log + continue)
const report = await upg.verify()
report.contentValidationErrors.forEach(e => console.warn(e.path, e.message))See also