Test fixtures · v0.6.2

Deterministic stub data for graph-shaped APIs.

Stubgraph generates stable, schema-aware fixtures that respect the relationships in your data — users link to posts, posts link back to authors. Same seed, same graph, every run and every machine.

$ npm i -D stubgraph

Quick start

Describe the shape, get the graph

Declare each node type and how it relates to the others. Stubgraph wires the references together and fills the fields from a seed. Cyclic relations and back-references resolve automatically.

Works as a library or on the command line. Output is plain JSON — drop it into tests, MSW handlers, Storybook, or a local mock server.

fixtures.ts
import { graph, seed } from "stubgraph";

const data = graph({
  user: { id: "uuid", name: "name.full", posts: ["post"] },
  post: { id: "uuid", title: "lorem.sentence", author: "user" },
}, { seed: 42, counts: { user: 5, post: 20 } });

// same seed -> identical graph, deterministic refs
data.user[0].posts[0].author.id === data.user[0].id;

Why stubgraph

Fixtures that don't drift

Most fakers give you random rows with no relationships. Stubgraph treats your data as a graph and keeps it consistent across every run.

Deterministic by default

Every value derives from a seed. Snapshots, golden files and CI stay stable because the graph never shifts between runs or machines.

Schema-aware

Feed it a GraphQL SDL or a JSON schema and Stubgraph honours relations, enums, nullability and back-references with no extra wiring.

Zero runtime deps

One small package. No native bindings, no postinstall scripts, nothing unexpected added to your lockfile or your audit log.

Changelog

Recent releases

Stubgraph follows semantic versioning. Breaking changes are reserved for major bumps.