fraiseql_cli/cli.rs
1//! CLI argument definitions: `Cli` struct, `Commands` enum, and all sub-command enums.
2
3use clap::{Parser, Subcommand};
4
5/// Exit codes documented in help text
6pub(crate) const EXIT_CODES_HELP: &str = "\
7EXIT CODES:
8 0 Success - Command completed successfully
9 1 Error - Command failed with an error
10 2 Validation failed - Schema or input validation failed";
11
12/// FraiseQL CLI - Compile GraphQL schemas to optimized SQL execution
13#[derive(Parser)]
14#[command(name = "fraiseql")]
15#[command(author, version, about, long_about = None)]
16#[command(propagate_version = true)]
17#[command(after_help = EXIT_CODES_HELP)]
18pub(crate) struct Cli {
19 /// Enable verbose logging
20 #[arg(short, long, global = true)]
21 pub(crate) verbose: bool,
22
23 /// Enable debug logging
24 #[arg(short, long, global = true)]
25 pub(crate) debug: bool,
26
27 /// Output as JSON (machine-readable)
28 #[arg(long, global = true)]
29 pub(crate) json: bool,
30
31 /// Suppress output (exit code only)
32 #[arg(short, long, global = true)]
33 pub(crate) quiet: bool,
34
35 #[command(subcommand)]
36 pub(crate) command: Commands,
37}
38
39#[derive(Subcommand)]
40pub(crate) enum Commands {
41 /// Compile schema to optimized schema.compiled.json
42 ///
43 /// Supports three workflows:
44 /// 1. TOML-only: fraiseql compile fraiseql.toml
45 /// 2. Language + TOML: fraiseql compile fraiseql.toml --types types.json
46 /// 3. Legacy JSON: fraiseql compile schema.json
47 #[command(after_help = "\
48EXAMPLES:
49 fraiseql compile fraiseql.toml
50 fraiseql compile fraiseql.toml --types types.json
51 fraiseql compile schema.json -o schema.compiled.json
52 fraiseql compile fraiseql.toml --check")]
53 Compile {
54 /// Input file path: fraiseql.toml (TOML) or schema.json (legacy)
55 #[arg(value_name = "INPUT")]
56 input: String,
57
58 /// Optional types.json from language implementation (used with fraiseql.toml)
59 #[arg(long, value_name = "TYPES")]
60 types: Option<String>,
61
62 /// Directory for auto-discovery of schema files (recursive *.json)
63 #[arg(long, value_name = "DIR")]
64 schema_dir: Option<String>,
65
66 /// Type files (repeatable): fraiseql compile fraiseql.toml --type-file a.json --type-file
67 /// b.json
68 #[arg(long = "type-file", value_name = "FILE")]
69 type_files: Vec<String>,
70
71 /// Query files (repeatable)
72 #[arg(long = "query-file", value_name = "FILE")]
73 query_files: Vec<String>,
74
75 /// Mutation files (repeatable)
76 #[arg(long = "mutation-file", value_name = "FILE")]
77 mutation_files: Vec<String>,
78
79 /// Output schema.compiled.json file path
80 #[arg(
81 short,
82 long,
83 value_name = "OUTPUT",
84 default_value = "schema.compiled.json"
85 )]
86 output: String,
87
88 /// Validate only, don't write output
89 #[arg(long)]
90 check: bool,
91
92 /// Skip embedding content hash in compiled schema (for test fixtures)
93 #[arg(long)]
94 skip_hash: bool,
95
96 /// Optional database URL for indexed column validation
97 /// When provided, validates that indexed columns exist in database views
98 #[arg(long, value_name = "DATABASE_URL")]
99 database: Option<String>,
100
101 /// Emit DDL files for all schema types to the given directory
102 ///
103 /// Writes `CREATE TABLE` DDL for each compiled type to `<DIR>/<type>.sql`.
104 /// Output is compatible with confiture's `db/schema/` directory format,
105 /// enabling `fraiseql migrate generate` to auto-detect schema drift.
106 #[arg(long, value_name = "DIR")]
107 emit_ddl: Option<String>,
108
109 /// Check compiled schema against the database for migration drift
110 ///
111 /// Emits DDL to a temporary directory, then delegates to
112 /// `confiture migrate validate` for drift detection.
113 /// Exits non-zero when the compiled schema diverges from the database.
114 #[arg(long)]
115 check_migrations: bool,
116 },
117
118 /// Extract schema from annotated source files
119 ///
120 /// Parses FraiseQL annotations in any supported language and generates schema.json.
121 /// No language runtime required — pure text processing.
122 #[command(after_help = "\
123EXAMPLES:
124 fraiseql extract schema/schema.py
125 fraiseql extract schema/ --recursive
126 fraiseql extract schema.rs --language rust -o schema.json")]
127 Extract {
128 /// Source file(s) or directory to extract from
129 #[arg(value_name = "INPUT")]
130 input: Vec<String>,
131
132 /// Override language detection (python, typescript, rust, java, kotlin, go, csharp, swift,
133 /// scala)
134 #[arg(short, long)]
135 language: Option<String>,
136
137 /// Recursively scan directories
138 #[arg(short, long)]
139 recursive: bool,
140
141 /// Output file path
142 #[arg(short, long, default_value = "schema.json")]
143 output: String,
144 },
145
146 /// Explain query execution plan and complexity
147 ///
148 /// Shows GraphQL query execution plan, SQL, and complexity analysis.
149 #[command(after_help = "\
150EXAMPLES:
151 fraiseql explain '{ users { id name } }'
152 fraiseql explain '{ user(id: 1) { posts { title } } }' --json")]
153 Explain {
154 /// GraphQL query string
155 #[arg(value_name = "QUERY")]
156 query: String,
157 },
158
159 /// Calculate query complexity score
160 ///
161 /// Quick analysis of query complexity (depth, field count, score).
162 #[command(after_help = "\
163EXAMPLES:
164 fraiseql cost '{ users { id name } }'
165 fraiseql cost '{ deeply { nested { query { here } } } }' --json")]
166 Cost {
167 /// GraphQL query string
168 #[arg(value_name = "QUERY")]
169 query: String,
170 },
171
172 /// Analyze schema for optimization opportunities
173 ///
174 /// Provides recommendations across 6 categories:
175 /// performance, security, federation, complexity, caching, indexing
176 #[command(after_help = "\
177EXAMPLES:
178 fraiseql analyze schema.compiled.json
179 fraiseql analyze schema.compiled.json --json")]
180 Analyze {
181 /// Path to schema.compiled.json
182 #[arg(value_name = "SCHEMA")]
183 schema: String,
184 },
185
186 /// Analyze schema type dependencies
187 ///
188 /// Exports dependency graph, detects cycles, and finds unused types.
189 /// Supports multiple output formats for visualization and CI integration.
190 #[command(after_help = "\
191EXAMPLES:
192 fraiseql dependency-graph schema.compiled.json
193 fraiseql dependency-graph schema.compiled.json -f dot > graph.dot
194 fraiseql dependency-graph schema.compiled.json -f mermaid
195 fraiseql dependency-graph schema.compiled.json --json")]
196 DependencyGraph {
197 /// Path to schema.compiled.json
198 #[arg(value_name = "SCHEMA")]
199 schema: String,
200
201 /// Output format (json, dot, mermaid, d2, console)
202 #[arg(short, long, value_name = "FORMAT", default_value = "json")]
203 format: String,
204 },
205
206 /// Export federation dependency graph
207 ///
208 /// Visualize federation structure in multiple formats.
209 #[command(after_help = "\
210EXAMPLES:
211 fraiseql federation graph schema.compiled.json
212 fraiseql federation graph schema.compiled.json -f dot
213 fraiseql federation graph schema.compiled.json -f mermaid")]
214 Federation {
215 /// Schema path (positional argument passed to subcommand)
216 #[command(subcommand)]
217 command: FederationCommands,
218 },
219
220 /// Lint schema for FraiseQL design quality
221 ///
222 /// Analyzes schema using FraiseQL-calibrated design rules.
223 /// Detects JSONB batching issues, compilation problems, auth boundaries, etc.
224 #[command(after_help = "\
225EXAMPLES:
226 fraiseql lint schema.json
227 fraiseql lint schema.compiled.json --federation
228 fraiseql lint schema.json --fail-on-critical
229 fraiseql lint schema.json --json")]
230 Lint {
231 /// Path to schema.json or schema.compiled.json
232 #[arg(value_name = "SCHEMA")]
233 schema: String,
234
235 /// Only show federation audit
236 #[arg(long)]
237 federation: bool,
238
239 /// Only show cost audit
240 #[arg(long)]
241 cost: bool,
242
243 /// Only show cache audit
244 #[arg(long)]
245 cache: bool,
246
247 /// Only show auth audit
248 #[arg(long)]
249 auth: bool,
250
251 /// Only show compilation audit
252 #[arg(long)]
253 compilation: bool,
254
255 /// Exit with error if any critical issues found
256 #[arg(long)]
257 fail_on_critical: bool,
258
259 /// Exit with error if any warning or critical issues found
260 #[arg(long)]
261 fail_on_warning: bool,
262 },
263
264 /// Generate DDL for Arrow views (va_*, tv_*, ta_*)
265 #[command(after_help = "\
266EXAMPLES:
267 fraiseql generate-views -s schema.json -e User --view va_users
268 fraiseql generate-views -s schema.json -e Order --view tv_orders --refresh-strategy scheduled")]
269 GenerateViews {
270 /// Path to schema.json
271 #[arg(short, long, value_name = "SCHEMA")]
272 schema: String,
273
274 /// Entity name from schema
275 #[arg(short, long, value_name = "NAME")]
276 entity: String,
277
278 /// View name (must start with va_, tv_, or ta_)
279 #[arg(long, value_name = "NAME")]
280 view: String,
281
282 /// Refresh strategy (trigger-based or scheduled)
283 #[arg(long, value_name = "STRATEGY", default_value = "trigger-based")]
284 refresh_strategy: String,
285
286 /// Output file path (default: {view}.sql)
287 #[arg(short, long, value_name = "PATH")]
288 output: Option<String>,
289
290 /// Include helper/composition views
291 #[arg(long, default_value = "true")]
292 include_composition_views: bool,
293
294 /// Include monitoring functions
295 #[arg(long, default_value = "true")]
296 include_monitoring: bool,
297
298 /// Validate only, don't write file
299 #[arg(long)]
300 validate: bool,
301
302 /// Show generation steps (use global --verbose flag)
303 #[arg(long, action = clap::ArgAction::SetTrue)]
304 gen_verbose: bool,
305 },
306
307 /// Generate external-write capture-trigger DDL for @subscribable types (#366)
308 ///
309 /// Emits a self-contained, idempotent PostgreSQL script (the capture function
310 /// plus per-table statement-level triggers) that brings raw external writes
311 /// (psql / migrations / third-party tools) to a `@subscribable` type's table(s)
312 /// onto the Change Spine, without double-emitting for FraiseQL-mediated writes.
313 #[command(after_help = "\
314EXAMPLES:
315 fraiseql generate-capture-triggers -s schema.compiled.json | psql \"$DATABASE_URL\"
316 fraiseql generate-capture-triggers -s schema.compiled.json -o capture.sql")]
317 GenerateCaptureTriggers {
318 /// Path to the compiled schema (schema.compiled.json)
319 #[arg(short, long, value_name = "SCHEMA")]
320 schema: String,
321
322 /// Output file path (default: stdout, for piping into psql)
323 #[arg(short, long, value_name = "PATH")]
324 output: Option<String>,
325
326 /// Omit the capture function definition (emit only the per-table triggers)
327 #[arg(long)]
328 no_function: bool,
329 },
330
331 /// Validate schema.json or fact tables
332 ///
333 /// Performs comprehensive schema validation including:
334 /// - JSON structure validation
335 /// - Type reference validation
336 /// - Circular dependency detection (with --check-cycles)
337 /// - Unused type detection (with --check-unused)
338 #[command(after_help = "\
339EXAMPLES:
340 fraiseql validate schema.json
341 fraiseql validate schema.json --check-unused
342 fraiseql validate schema.json --strict
343 fraiseql validate facts -s schema.json -d postgres://localhost/db")]
344 Validate {
345 #[command(subcommand)]
346 command: Option<ValidateCommands>,
347
348 /// Schema.json file path to validate (if no subcommand)
349 #[arg(value_name = "INPUT")]
350 input: Option<String>,
351
352 /// Check for circular dependencies between types
353 #[arg(long, default_value = "true")]
354 check_cycles: bool,
355
356 /// Check for unused types (no incoming references)
357 #[arg(long)]
358 check_unused: bool,
359
360 /// Strict mode: treat warnings as errors (unused types become errors)
361 #[arg(long)]
362 strict: bool,
363
364 /// Only analyze specific type(s) - comma-separated list
365 #[arg(long, value_name = "TYPES", value_delimiter = ',')]
366 types: Vec<String>,
367
368 /// Validate the mutation contract against a live PostgreSQL database.
369 ///
370 /// For each DB-backed mutation, checks that its `sql_source` function
371 /// exists with the argument layout the server sends and returns the
372 /// columns the server decodes into `MutationResponse`. Requires a
373 /// compiled schema (schema.compiled.json) as INPUT. (#397)
374 #[arg(long, value_name = "DATABASE_URL")]
375 against_db: Option<String>,
376 },
377
378 /// Introspect database for fact tables and output suggestions
379 #[command(after_help = "\
380EXAMPLES:
381 fraiseql introspect facts -d postgres://localhost/db
382 fraiseql introspect facts -d postgres://localhost/db -f json")]
383 Introspect {
384 #[command(subcommand)]
385 command: IntrospectCommands,
386 },
387
388 /// Generate authoring-language source from schema.json
389 ///
390 /// The inverse of `fraiseql extract`: reads a schema.json and produces annotated
391 /// source code in any of the 9 supported authoring languages.
392 #[command(after_help = "\
393EXAMPLES:
394 fraiseql generate schema.json --language python
395 fraiseql generate schema.json --language rust -o schema.rs
396 fraiseql generate schema.json --language typescript")]
397 Generate {
398 /// Path to schema.json
399 #[arg(value_name = "INPUT")]
400 input: String,
401
402 /// Target language (python, typescript, rust, java, kotlin, go, csharp, swift, scala)
403 #[arg(short, long)]
404 language: String,
405
406 /// Output file path (default: schema.<ext> based on language)
407 #[arg(short, long)]
408 output: Option<String>,
409 },
410
411 /// Generate consumer-side typed clients from a compiled schema
412 ///
413 /// Distinct from `generate`: `generate` emits server-side authoring code (write
414 /// FraiseQL types in another language, fed back into the compiler), whereas
415 /// `generate-client` emits a typed client for callers of a FraiseQL API
416 /// (interfaces + query/mutation functions) from a compiled schema.compiled.json.
417 #[command(after_help = "\
418EXAMPLES:
419 fraiseql generate-client typescript --out ./src/generated
420 fraiseql generate-client typescript --schema ./schema.compiled.json --out ./gen --force")]
421 GenerateClient {
422 #[command(subcommand)]
423 language: GenerateClientCommands,
424 },
425
426 /// Initialize a new FraiseQL project
427 ///
428 /// Creates project directory with fraiseql.toml, schema.json,
429 /// database DDL structure, and authoring skeleton.
430 #[command(after_help = "\
431EXAMPLES:
432 fraiseql init my-app
433 fraiseql init my-app --language typescript --database postgres
434 fraiseql init my-app --size xs --no-git")]
435 Init {
436 /// Project name (used as directory name)
437 #[arg(value_name = "PROJECT_NAME")]
438 project_name: String,
439
440 /// Authoring language (python, typescript, rust, java, kotlin, go, csharp, swift, scala)
441 #[arg(short, long, default_value = "python")]
442 language: String,
443
444 /// Target database (postgres, mysql, sqlite, sqlserver)
445 #[arg(long, default_value = "postgres")]
446 database: String,
447
448 /// Project size: xs (single file), s (flat dirs), m (per-entity dirs)
449 #[arg(long, default_value = "s")]
450 size: String,
451
452 /// Skip git init
453 #[arg(long)]
454 no_git: bool,
455 },
456
457 /// Run database migrations
458 ///
459 /// Wraps confiture for a unified migration experience.
460 /// Reads database URL from --database, fraiseql.toml, or DATABASE_URL env var.
461 #[command(after_help = "\
462EXAMPLES:
463 fraiseql migrate up --database postgres://localhost/mydb
464 fraiseql migrate down --steps 1
465 fraiseql migrate status
466 fraiseql migrate create add_posts_table")]
467 Migrate {
468 #[command(subcommand)]
469 command: MigrateCommands,
470 },
471
472 /// Generate Software Bill of Materials
473 ///
474 /// Parses Cargo.lock and fraiseql.toml to produce a compliance-ready SBOM.
475 #[command(after_help = "\
476EXAMPLES:
477 fraiseql sbom
478 fraiseql sbom --format spdx
479 fraiseql sbom --format cyclonedx --output sbom.json")]
480 Sbom {
481 /// Output format (cyclonedx, spdx)
482 #[arg(short, long, default_value = "cyclonedx")]
483 format: String,
484
485 /// Output file path (default: stdout)
486 #[arg(short, long, value_name = "FILE")]
487 output: Option<String>,
488 },
489
490 /// Compile schema and immediately start the GraphQL server
491 ///
492 /// Compiles the schema in-memory (no disk artifact) and starts the HTTP server.
493 /// With --watch, the server hot-reloads whenever the schema file changes.
494 ///
495 /// Server and database settings can be declared in fraiseql.toml under [server]
496 /// and [database] sections. CLI flags take precedence over TOML settings, which
497 /// take precedence over defaults. The database URL is resolved in this order:
498 /// --database flag > DATABASE_URL env var > [database].url in fraiseql.toml.
499 #[cfg(feature = "run-server")]
500 #[command(after_help = "\
501EXAMPLES:
502 fraiseql run
503 fraiseql run fraiseql.toml --database postgres://localhost/mydb
504 fraiseql run --port 3000 --watch
505 fraiseql run schema.json --introspection
506
507TOML CONFIG:
508 [server]
509 host = \"127.0.0.1\"
510 port = 9000
511
512 [server.cors]
513 origins = [\"https://app.example.com\"]
514
515 [database]
516 url = \"${DATABASE_URL}\"
517 pool_min = 2
518 pool_max = 20")]
519 Run {
520 /// Input file path (fraiseql.toml or schema.json); auto-detected if omitted
521 #[arg(value_name = "INPUT")]
522 input: Option<String>,
523
524 /// Database URL (overrides [database].url in fraiseql.toml and DATABASE_URL env var)
525 #[arg(short, long, value_name = "DATABASE_URL")]
526 database: Option<String>,
527
528 /// Port to listen on (overrides [server].port in fraiseql.toml)
529 #[arg(short, long, value_name = "PORT")]
530 port: Option<u16>,
531
532 /// Bind address (overrides [server].host in fraiseql.toml)
533 #[arg(long, value_name = "HOST")]
534 bind: Option<String>,
535
536 /// Watch input file for changes and hot-reload the server
537 #[arg(short, long)]
538 watch: bool,
539
540 /// Enable the GraphQL introspection endpoint (no auth required)
541 #[arg(long)]
542 introspection: bool,
543 },
544
545 /// Watch a schema source and recompile + live-reload a running server on change
546 ///
547 /// Recompiles `schema.compiled.json` on every save and, with `--reload-url`,
548 /// POSTs it to a running server's `/api/v1/admin/reload-schema` endpoint for a
549 /// zero-downtime `ArcSwap` reload (no restart). Unlike `run --watch`, this drives
550 /// a server you started separately.
551 Watch {
552 /// Schema source to watch (fraiseql.toml or schema.json)
553 #[arg(value_name = "INPUT")]
554 input: String,
555
556 /// Compiled-schema output path (the server reads this on reload)
557 #[arg(short, long, default_value = "schema.compiled.json")]
558 output: String,
559
560 /// Base URL of a running server to live-reload (e.g. http://localhost:8080).
561 /// Omit to recompile to disk only.
562 #[arg(long, value_name = "URL")]
563 reload_url: Option<String>,
564
565 /// Bearer token for the server's admin reload endpoint
566 #[arg(long, value_name = "TOKEN")]
567 admin_token: Option<String>,
568
569 /// Database URL for compile-time validation (overrides DATABASE_URL)
570 #[arg(long, value_name = "DATABASE_URL")]
571 database: Option<String>,
572 },
573
574 /// Validate a trusted documents manifest
575 ///
576 /// Checks that the manifest JSON is well-formed and that each key
577 /// is a valid SHA-256 hex string matching its query body.
578 #[command(after_help = "\
579EXAMPLES:
580 fraiseql validate-documents manifest.json")]
581 ValidateDocuments {
582 /// Path to the trusted documents manifest JSON file
583 #[arg(value_name = "MANIFEST")]
584 manifest: String,
585 },
586
587 /// Install FraiseQL mutation helper functions
588 ///
589 /// Installs SQL helper functions (fraiseql.mutation_ok, fraiseql.mutation_err, etc.)
590 /// to reduce boilerplate when writing mutation functions under the v2.2.0 protocol.
591 /// The helpers are installed in the `fraiseql` schema, which is owned by FraiseQL's
592 /// database role.
593 #[command(after_help = "\
594EXAMPLES:
595 fraiseql setup --database postgres://localhost/mydb
596 fraiseql setup --dry-run
597 fraiseql setup # Uses DATABASE_URL or [database].url from fraiseql.toml")]
598 Setup {
599 /// Database connection URL (or use DATABASE_URL env var, or [database].url in
600 /// fraiseql.toml)
601 #[arg(long, value_name = "DATABASE_URL")]
602 database: Option<String>,
603
604 /// Print SQL without applying changes
605 #[arg(long)]
606 dry_run: bool,
607 },
608
609 /// Inspect schema metadata from a running FraiseQL server
610 ///
611 /// Fetches field-level security metadata (encryption, scope requirements, deny actions)
612 /// from the server's `/api/v1/schema/metadata` endpoint and displays it as a table.
613 #[command(after_help = "\
614EXAMPLES:
615 fraiseql schema metadata
616 fraiseql schema metadata --server http://localhost:8080
617 fraiseql schema metadata --server https://api.example.com --token mytoken")]
618 Schema {
619 #[command(subcommand)]
620 command: SchemaCommands,
621 },
622
623 /// Run diagnostic checks for common FraiseQL setup problems
624 ///
625 /// Checks schema file, TOML config, DATABASE_URL, JWT secret, Redis, TLS,
626 /// and cache/auth coherence. Prints a color-coded report and exits 0 if
627 /// all checks pass or 1 if any check fails (warnings do not fail).
628 #[command(after_help = "\
629EXAMPLES:
630 fraiseql doctor
631 fraiseql doctor --schema schema.compiled.json --config fraiseql.toml
632 fraiseql doctor --db-url postgres://user:pass@host:5432/db
633 fraiseql doctor --json")]
634 Doctor {
635 /// Path to fraiseql.toml configuration file.
636 #[arg(long, default_value = "fraiseql.toml")]
637 config: std::path::PathBuf,
638
639 /// Path to schema.compiled.json.
640 #[arg(long, default_value = "schema.compiled.json")]
641 schema: std::path::PathBuf,
642
643 /// Override DATABASE_URL for the connectivity check.
644 #[arg(long)]
645 db_url: Option<String>,
646
647 /// Run the live-database passes against this PostgreSQL database: the
648 /// change-log contract drift check (compares core.tb_entity_change_log
649 /// against the shipped contract — #380), the PL/pgSQL body-resolution
650 /// pass (reports internal calls that no longer resolve — #409), and the
651 /// mutation→function contract drift check (every declared mutation has a
652 /// matching backing function with a mutation_response-shaped return —
653 /// #384).
654 ///
655 /// The body-resolution pass requires the `plpgsql_check` extension and
656 /// skips with a hint when it is unavailable.
657 #[arg(long, value_name = "DATABASE_URL")]
658 against_db: Option<String>,
659
660 /// Schemas to scan in the body-resolution pass (comma-separated).
661 #[arg(
662 long,
663 value_name = "SCHEMAS",
664 value_delimiter = ',',
665 default_value = "public"
666 )]
667 schemas: Vec<String>,
668
669 /// Output machine-readable JSON (for CI integration).
670 #[arg(long)]
671 json: bool,
672 },
673
674 /// Change-log performance observability (#392)
675 ///
676 /// Reads the framework-owned change-log (`core.v_entity_change_log`) and turns
677 /// it into operator-facing forensics: latency regressions between two time
678 /// windows, and ad-hoc reads of the slowest mutations / duration completeness
679 /// / per-operation percentiles.
680 Perf {
681 #[command(subcommand)]
682 command: PerfCommands,
683 },
684}
685
686/// `fraiseql perf` subcommands.
687#[derive(Subcommand)]
688pub(crate) enum PerfCommands {
689 /// Flag mutations whose latency regressed between a baseline and a recent
690 /// window, per `(object_type, modification_type)`.
691 ///
692 /// Only rows carrying the current `duration_calc_version` are compared, and
693 /// latency is never aggregated across modification types — so a shift in the
694 /// operation mix cannot mask a regression as a false improvement. Exits 0 even
695 /// when regressions are found (it is a report); pass `--fail-on-regression`
696 /// for CI gating.
697 RegressionScan {
698 /// PostgreSQL URL (defaults to `fraiseql.toml` / `DATABASE_URL`).
699 #[arg(long, value_name = "DATABASE_URL")]
700 database: Option<String>,
701
702 /// Recent window size, in days.
703 #[arg(long, default_value_t = 7)]
704 recent_days: i64,
705
706 /// Baseline window size (immediately before the recent window), in days.
707 #[arg(long, default_value_t = 7)]
708 baseline_days: i64,
709
710 /// Minimum comparable samples required on each side; thinner groups are
711 /// skipped rather than flagged.
712 #[arg(long, default_value_t = 20)]
713 min_samples: usize,
714
715 /// Minimum p50 increase to flag, in percent.
716 #[arg(long, default_value_t = 25.0)]
717 threshold_pct: f64,
718
719 /// Minimum absolute p50 increase to flag, in milliseconds (the noise floor).
720 #[arg(long, default_value_t = 5.0)]
721 min_delta_ms: f64,
722
723 /// Restrict the scan to a single object_type.
724 #[arg(long, value_name = "TYPE")]
725 object_type: Option<String>,
726
727 /// Exit non-zero when any regression is found (for CI gating).
728 #[arg(long)]
729 fail_on_regression: bool,
730 },
731
732 /// Ad-hoc forensic reads of the change-log.
733 Explore {
734 #[command(subcommand)]
735 command: PerfExploreCommands,
736 },
737}
738
739/// `fraiseql perf explore` subcommands — read-only views over comparable (v2)
740/// change-log rows in a trailing window.
741#[derive(Subcommand)]
742pub(crate) enum PerfExploreCommands {
743 /// The slowest individual mutations, slowest first.
744 Slowest {
745 /// PostgreSQL URL (defaults to `fraiseql.toml` / `DATABASE_URL`).
746 #[arg(long, value_name = "DATABASE_URL")]
747 database: Option<String>,
748
749 /// Trailing window to scan, in days.
750 #[arg(long, default_value_t = 7)]
751 days: i32,
752
753 /// Restrict to a single object_type.
754 #[arg(long, value_name = "TYPE")]
755 object_type: Option<String>,
756
757 /// Maximum rows to return.
758 #[arg(long, default_value_t = 20)]
759 limit: usize,
760 },
761
762 /// `duration_ms` completeness (NULL / pre-fix rates), per operation.
763 NullRate {
764 /// PostgreSQL URL (defaults to `fraiseql.toml` / `DATABASE_URL`).
765 #[arg(long, value_name = "DATABASE_URL")]
766 database: Option<String>,
767
768 /// Trailing window to scan, in days.
769 #[arg(long, default_value_t = 7)]
770 days: i32,
771
772 /// Restrict to a single object_type.
773 #[arg(long, value_name = "TYPE")]
774 object_type: Option<String>,
775 },
776
777 /// Latency percentiles (p50/p95/p99/max), per operation.
778 Summary {
779 /// PostgreSQL URL (defaults to `fraiseql.toml` / `DATABASE_URL`).
780 #[arg(long, value_name = "DATABASE_URL")]
781 database: Option<String>,
782
783 /// Trailing window to scan, in days.
784 #[arg(long, default_value_t = 7)]
785 days: i32,
786
787 /// Restrict to a single object_type.
788 #[arg(long, value_name = "TYPE")]
789 object_type: Option<String>,
790 },
791}
792
793#[derive(Subcommand)]
794pub(crate) enum ValidateCommands {
795 /// Validate that declared fact tables match database schema
796 Facts {
797 /// Schema.json file path
798 #[arg(short, long, value_name = "SCHEMA")]
799 schema: String,
800
801 /// Database connection string
802 #[arg(short, long, value_name = "DATABASE_URL")]
803 database: String,
804 },
805}
806
807#[derive(Subcommand)]
808pub(crate) enum GenerateClientCommands {
809 /// Generate a TypeScript client (interfaces + typed query/mutation functions).
810 Typescript {
811 /// Path to schema.compiled.json (auto-detected from conventional
812 /// locations if omitted).
813 #[arg(long, value_name = "SCHEMA")]
814 schema: Option<std::path::PathBuf>,
815
816 /// Output directory for the generated client.
817 #[arg(long, value_name = "DIR")]
818 out: std::path::PathBuf,
819
820 /// Overwrite an existing generated client in the output directory.
821 #[arg(long, default_value_t = false)]
822 force: bool,
823 },
824}
825
826#[derive(Subcommand)]
827pub(crate) enum FederationCommands {
828 /// Export federation graph
829 Graph {
830 /// Path to schema.compiled.json
831 #[arg(value_name = "SCHEMA")]
832 schema: String,
833
834 /// Output format (json, dot, mermaid)
835 #[arg(short, long, value_name = "FORMAT", default_value = "json")]
836 format: String,
837 },
838
839 /// Validate subgraph composition
840 Check {
841 /// Path to local schema.compiled.json
842 #[arg(value_name = "SCHEMA")]
843 schema: String,
844
845 /// Path to supergraph schema for composition validation
846 #[arg(short, long, value_name = "SUPERGRAPH")]
847 against: Option<String>,
848
849 /// Output result as JSON
850 #[arg(long)]
851 json: bool,
852 },
853}
854
855#[derive(Subcommand)]
856pub(crate) enum IntrospectCommands {
857 /// Introspect database for fact tables (tf_* tables)
858 Facts {
859 /// Database connection string
860 #[arg(short, long, value_name = "DATABASE_URL")]
861 database: String,
862
863 /// Output format (python, json)
864 #[arg(short, long, value_name = "FORMAT", default_value = "python")]
865 format: String,
866 },
867}
868
869#[derive(Subcommand)]
870pub(crate) enum SchemaCommands {
871 /// Display field-level security metadata from a running server
872 Metadata {
873 /// Server base URL
874 #[arg(
875 short,
876 long,
877 value_name = "URL",
878 default_value = "http://localhost:8080"
879 )]
880 server: String,
881
882 /// Bearer token for authentication
883 #[arg(short, long, value_name = "TOKEN")]
884 token: Option<String>,
885 },
886}
887
888#[derive(Subcommand)]
889pub(crate) enum MigrateCommands {
890 /// Apply pending migrations
891 Up {
892 /// Database connection URL
893 #[arg(long, value_name = "DATABASE_URL")]
894 database: Option<String>,
895
896 /// Migration directory
897 #[arg(long, value_name = "DIR")]
898 dir: Option<String>,
899 },
900
901 /// Roll back migrations
902 Down {
903 /// Database connection URL
904 #[arg(long, value_name = "DATABASE_URL")]
905 database: Option<String>,
906
907 /// Migration directory
908 #[arg(long, value_name = "DIR")]
909 dir: Option<String>,
910
911 /// Number of migrations to roll back
912 #[arg(long, default_value = "1")]
913 steps: u32,
914 },
915
916 /// Show migration status
917 Status {
918 /// Database connection URL
919 #[arg(long, value_name = "DATABASE_URL")]
920 database: Option<String>,
921
922 /// Migration directory
923 #[arg(long, value_name = "DIR")]
924 dir: Option<String>,
925 },
926
927 /// Create a new migration file
928 Create {
929 /// Migration name
930 #[arg(value_name = "NAME")]
931 name: String,
932
933 /// Migration directory
934 #[arg(long, value_name = "DIR")]
935 dir: Option<String>,
936 },
937
938 /// Generate a new migration from schema diff
939 ///
940 /// Delegates to `confiture migrate generate`.
941 /// Creates a timestamped migration file.
942 Generate {
943 /// Migration name
944 #[arg(value_name = "NAME")]
945 name: String,
946
947 /// Migration directory
948 #[arg(long, value_name = "DIR")]
949 dir: Option<String>,
950 },
951
952 /// Validate migration files for naming, idempotency, and drift
953 ///
954 /// Delegates to `confiture migrate validate`.
955 /// Checks naming conventions, idempotency, and schema drift.
956 Validate {
957 /// Migration directory
958 #[arg(long, value_name = "DIR")]
959 dir: Option<String>,
960 },
961
962 /// Pre-deploy safety check on pending migrations
963 ///
964 /// Delegates to `confiture migrate preflight`.
965 /// Verifies reversibility, detects non-transactional statements, checks checksums.
966 Preflight {
967 /// Migration directory
968 #[arg(long, value_name = "DIR")]
969 dir: Option<String>,
970 },
971}