turbo
7acfdc43 - refactor: Extract `turborepo-query-api` trait crate for compile-time decoupling (#12165)

Commit
57 days ago
refactor: Extract `turborepo-query-api` trait crate for compile-time decoupling (#12165) ## Summary - Introduces `turborepo-query-api`, a trait crate defining `QueryServer` and `QueryRun` that decouples `turborepo-lib` from the heavy `turborepo-query` crate (async-graphql, axum, oxc), enabling parallel compilation - The binary crate wires the two halves together via `TurboQueryServer`, implementing the dependency inversion pattern ## Key design decisions **Error composition over duplication.** Rather than duplicating error variants between crates with a fragile manual `From` impl, `turborepo-query::Error` wraps `turborepo_query_api::Error` via an `Api(#[from] ...)` variant. Shared errors (Boundaries, Server, Path, UI, etc.) flow through automatically. Query-specific errors (Trace, FileNotFound, Serde, Parse) stay local and get boxed only when crossing the boundary. **Resolution errors preserve diagnostics.** Added `Resolution` variant with `#[diagnostic(transparent)]` to the API error enum so miette source spans survive the full error chain from query → API → CLI. **Watch mode threading.** `WatchClient` now accepts and forwards `query_server` to all 3 `RunBuilder` call sites, fixing a silent Web UI regression where `turbo watch --ui=web` would produce no UI and no error. **Unified error type on `QueryServer`.** All three trait methods now return `Result<_, turborepo_query_api::Error>` instead of mixing in `turborepo_ui::Error`. ## How to test 1. `cargo check -p turbo --features rustls-tls` — verifies compilation 2. `cargo clippy -p turborepo-query-api -p turborepo-query -p turborepo-lib -p turbo --features rustls-tls` — zero warnings 3. Run `turbo query "{ packages { items { name } } }"` in any monorepo — should work as before 4. The `QueryNotAvailable` error can be verified by inspecting the code path (only reachable if someone uses `turborepo-lib` as a library without providing a query server)
Author
Parents
Loading