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 · Importing
A ~30-line adapter shape: parse the source, map each entity, persist via UPGClient, verify at the end.
Code
// adapter-markdown.ts
import { readdir, readFile } from 'node:fs/promises'
import matter from 'gray-matter'
import { UPGClient } from '@unified-product-graph/sdk'
export async function importMarkdownVault(dir: string, upg: UPGClient) {
const files = (await readdir(dir)).filter(f => f.endsWith('.md'))
let imported = 0
for (const file of files) {
const raw = await readFile(`${dir}/${file}`, 'utf-8')
const { data: front, content } = matter(raw)
const type = (front.type as string) ?? 'note'
const title = (front.title as string) ?? file.replace('.md', '')
await upg.nodes.create({
type,
title,
description: content.slice(0, 500),
tags: (front.tags as string[]) ?? [],
})
imported++
}
const report = await upg.verify()
const { score } = await upg.health()
console.log(`imported ${imported} · health ${score}/10`)
if (report.errors.length) console.warn('with warnings:', report.errors)
}Output
// click ▶ Run to see what this snippet would print locally