Flatbread's local loop has four moving parts:
- Loader reload — source plugins read flat files from the configured content paths.
- Schema rebuild —
@flatbread/coreturns loaded records and refs into a GraphQL schema after ID/ref validation. - Codegen refresh — the unified watcher regenerates TypeScript artifacts when config, content, or GraphQL documents change.
- Framework restart / refresh —
flatbread start -- <framework command>runs the GraphQL server beside your app command.
Today these pieces are automated by flatbread start --watch: content edits
incrementally reindex and hot-swap the GraphQL schema, config edits rebuild the
schema and watcher matchers, and document edits refresh codegen.
From the repo root:
pnpm install
pnpm build
cd examples/nextjs
pnpm exec flatbread codegen --verboseFor development, use the unified watcher. It serves GraphQL on port 5057,
refreshes generated artifacts, and runs Next.js. The example package's
pnpm dev script runs the same command.
pnpm exec flatbread start --watch -- next dev --turbopackExpected behavior:
- One unified watcher owns config/content/document classification, GraphQL hot-swaps, and generated artifact refreshes.
- Editing a
.graphqldocument or a content/config file refreshesgenerated/graphql.ts; do not runflatbread codegen --watchbeside it. - The generated content-model types and prototype read API are refreshed by the same codegen command.
- The running GraphQL endpoint at
http://localhost:5057/graphqlhot-swaps valid content and config generations without restarting the framework.
| Change | Unified watcher behavior | Running GraphQL server | Framework app | Action required today |
|---|---|---|---|---|
| Markdown/YAML field value | Atomically reindexes/hot-swaps, then refreshes codegen | Hot-swaps after validation | Keeps rendering whatever the endpoint returns | None; framework refresh remains explicit |
| New/removed content file | Atomically reindexes/hot-swaps, then refreshes codegen | Hot-swaps after validation | Keeps rendering whatever the endpoint returns | None; framework refresh remains explicit |
.graphql document |
Refreshes codegen only | No restart unless query text used by app changed | Framework dev server normally recompiles importing files | No Flatbread restart unless app code needs it |
flatbread.config.* content/ref change |
Reloads config/matchers, atomically rebuilds/hot-swaps, then refreshes codegen | Rebuilds and hot-swaps after validation | Keeps rendering whatever the endpoint returns | None; framework refresh remains explicit |
| Transformer/source package code | Does not rebuild package code | Keeps previous imported package code | May keep previous imported package code | Rebuild/watch package separately, rerun codegen, restart |
generated/graphql.ts |
Output of codegen | No direct effect | Framework dev server recompiles imports | No Flatbread restart |
- Rejected config, content, or codegen phases are logged and keep the unified watch loop alive. Existing generated files are left as-is until a later successful regeneration.
- In one-shot mode (
flatbread codegenwithout--watch), validation or codegen errors exit non-zero and do not prove the live server changed. - If the running GraphQL server was started before the invalid edit, it keeps serving the schema/data it already loaded. Restarting it surfaces the validation error at startup.
- In unified watch mode, invalid candidates are rejected atomically: generated artifacts and the live GraphQL server remain on the previous committed graph. A codegen failure does not undo an already committed GraphQL generation, and edits received during an in-flight generation are queued for the next serialized batch.
The unified loop is started with:
pnpm exec flatbread start --watch -- next dev --turbopackWatch mode does the following:
- A single coordinator classifies config, content, and document events, then serializes all rebuild and codegen phases.
- Content changes reindex records and atomically hot-swap the GraphQL schema before refreshing generated TypeScript.
- Config changes reload the config and matchers, rebuild and atomically hot-swap the schema, then refresh generated TypeScript.
- GraphQL document changes refresh generated TypeScript without reindexing content.
- Rejected phases emit an error but do not stop the loop. Committed GraphQL generations are not rolled back when a later codegen phase fails.
- Events received during an in-flight generation are queued and processed serially.
- Framework restarts remain explicit. Flatbread keeps the framework child process running and relies on its own dev server to recompile or refresh.
flatbread start --watchreplaces the running schema after a valid content or config change. If a change is invalid, it keeps the previous schema.- Watch mode is a long-running process; do not use it in CI or one-shot scripts.
- Flatbread serves plain HTTP. The
-H, --httpsflag does not change how it listens, so the GraphQL endpoint is always HTTP on5057. - Codegen failures are logged and do not undo a committed schema generation.
- Watch mode requires a source plugin with
fetchPaths; sources without it fail fast at startup. flatbread.config.*watching is relative to theflatbread startcwd.- Port
5057collisions are not resolved automatically; stop the old Flatbread process before starting another server.
Flatbread keeps the framework process running. It does not restart the framework or control how the framework refreshes its pages.