Build your own knowledge graph database
The record store·10 min

Load nodes & relationships

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage load-the-graph --watch

Bring the graph to life. Read the two JSON files into typed records and build the master lookups nodeById and relById. This is the GraphStore constructor in disguise — the foundation every later chapter builds on.

Your task

Implement GraphStore.fromJson and the constructor

Parse the raw arrays into Node[] / Relationship[], index them by id, and report counts. The load CLI command prints { nodeCount, relCount, sample }, where sample is the full record for The Matrix (node id 66).

src/store.ts
export class GraphStore {
  readonly nodeById = new Map<number, Node>();
  readonly relById = new Map<number, Relationship>();

  constructor(nodes: Node[], rels: Relationship[]) {
    for (const n of nodes) this.nodeById.set(n.id, n);
    for (const r of rels) this.relById.set(r.id, r);
    // (later chapters add adjacency + indexes here)
  }
  static fromJson(nodesJson: unknown, relsJson: unknown): GraphStore {
    return new GraphStore(nodesJson as Node[], relsJson as Relationship[]);
  }
}
Process command (what the grader runs)
your_program.sh load {fixture}/fixtures/data/nodes.json {fixture}/fixtures/data/relationships.json
# prints canonicalized JSON: {"nodeCount":87,"relCount":113,"sample":{...The Matrix...}}
How it's graded

Process mode, stdout_json_match: your printed JSON is deep-compared to fixtures/expected.json. Counts must be exact (87 / 113); the sampled record must deep-equal (object keys are compared as sets, so key order doesn't matter — print through canonicalizeValue).

Keep the property types intact

released: 1999 must stay an integer, and roles: ['Neo'] must stay a string[] — don't stringify arrays or coerce numbers to strings. Property types are graded explicitly in the next step.