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

Typed property access

0 / 1
# grade this stage (from your course directory)
npx theinference test --stage property-access --watch

A graph database is only useful if you can read attributes back with the right type. Implement getProperty(kind, id, key): look up the entity, return props[key] with its native type, or null when the key is missing. Graphs are schema-flexible — not every Person has born, and no Movie has a director property (that's a relationship, not an attribute).

Your task

Implement getProperty

Return the value with its native type, or null for an absent key. Distinguish null (absent) from a property that genuinely holds another value. The getprop CLI command reads three keys off The Matrix (id 66): title (string), released (int), and director (absent → null).

src/store.ts
getProperty(kind: "node" | "rel", id: number, key: string): Value | null {
  const entity = kind === "node" ? this.nodeById.get(id) : this.relById.get(id);
  if (!entity) return null;
  const v = entity.props[key];
  return v === undefined ? null : v;
}
Process command
your_program.sh getprop {fixture}/fixtures/data/nodes.json {fixture}/fixtures/data/relationships.json node 66 title released director
# -> ["The Matrix", 1999, null]
How it's graded

Process mode, stdout_json_match against ["The Matrix", 1999, null]. The comparison is type-sensitive: 1999 !== "1999", and null is not the same as a missing element. Return the integer as a number and the absent key as JSON null.