Repository navigation
feat(cli): add dataform compile --mermaid to output the dependency graph as a Mermaid flowchart - #2435
Merged
apilaskowski merged 3 commits intoNov 23, 2026
Conversation
rafal-hawrylak
requested changes
Nov 13, 2026
Collaborator
|
/gcbrun |
1 similar comment
Collaborator
|
/gcbrun |
rafal-hawrylak
approved these changes
Nov 16, 2026
apilaskowski
approved these changes
Nov 17, 2026
Collaborator
|
/gcbrun |
apilaskowski
force-pushed
the
feat/compile-mermaid-output
branch
from
November 23, 2026 01:53
527dd50 to
22ce4b9
Compare
Collaborator
|
/gcbrun |
apilaskowski
enabled auto-merge (squash)
November 23, 2026 02:01
…graph as a Mermaid flowchart Prints the same actions and dependencies as --dot as a Mermaid `graph LR` flowchart, which GitHub, GitLab and other Mermaid-enabled tools render natively. Works with the --output-* filters. - Node IDs are `n` plus 8 hex characters of a SHA-256 hash of the full target (only colliding IDs are lengthened), keeping diagrams within renderer size limits. - Labels show schema.name, plus the database when names are shared. Characters Mermaid would interpret are escaped; control characters are shown as Unicode control pictures. - Output is sorted by target, so regenerated diagrams diff cleanly. - Warns on stderr when the diagram exceeds Mermaid's default limits (500 edges, 50,000 characters). Closes dataform-co#2434
…abel bugs - Move mermaidRepresentation, mermaidSizeWarning, mermaidNodeIds and their helpers from cli/console.ts into cli/mermaid.ts, with their tests in cli/mermaid_test.ts. - Don't prefix a database to a label when the target has no database (e.g. a project with no defaultDatabase whose action shares its schema.name with a declaration elsewhere), which rendered ".analytics.users" or "undefined.analytics.users". - Derive the table type from the string `type` when `enumType` is unset, as prune() does, so graphs that only set the string type render "[table]" rather than "[unknown_type]" (or a TypeError) when compiled without --output-actions/--output-tags. Works on a copy, so the graph passed in is unchanged.
dotRepresentation had the same gap as mermaidRepresentation: graphs that only set the string `type` render "[unknown_type]" (or throw a TypeError when enumType is unset) when compiled without --output-actions or --output-tags, because prune() is skipped. - Move tableTypeLabel from cli/mermaid.ts to cli/util.ts and use it in both dotRepresentation and mermaidRepresentation. - Add a dotRepresentation test in cli/console_test.ts for an in-memory graph with only `type` set and a protobuf round-tripped one, checking the input is unchanged.
apilaskowski
force-pushed
the
feat/compile-mermaid-output
branch
from
November 23, 2026 02:03
22ce4b9 to
622b5db
Compare
Collaborator
|
/gcbrun |
apilaskowski
pushed a commit
that referenced
this pull request
Nov 23, 2026
Bump DF_VERSION from 3.1.6 to 3.1.7 to publish a new patch release of @dataform/core and @dataform/cli to npm. This release includes operations without hasOutput omitting dataset (#2476), domain project target and graph validation fixes (#2471), multiline rowConditions assertion fixes (#2424), BigQuery primitive field mappings (#2446), Mermaid graph output (#2435) and npm dependency security updates (#2472 and #2473). Publishing 3.1.7 allows projects to pin dataformCoreVersion to 3.1.7 in workflow_settings.yaml and install the updated CLI.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #2434.
Problem
dataform compile --dotoutput usually has to be turned into an image before it can be shared. GitHub, GitLab and other Mermaid-enabled documentation tools render Mermaid natively in Markdown. The main use case is a filtered diagram pasted where people review changes, e.g. a table and everything upstream of it in a PR description:Changes
--mermaidflag ondataform compile, mutually exclusive with--jsonand--dot. It shows the same actions and dependencies as--dot, and works with the existing--output-*filters.graph LR, which Azure DevOps wikis also support (they don't support the newerflowchartkeyword). Tables are labelled with their table type, and dependencies outside the selection (e.g. declarations) appear as plain nodes.schema.name, plus the database when several nodes share the sameschema.name(targets without a database, e.g. in a project with nodefaultDatabase, keep the plainschema.name). Table types are read from the stringtypewhenenumTypeisn't set, asprune()does, so labels are the same with or without--output-*filters. Characters Mermaid would interpret (",#,&,<,>, backticks, backslashes, colons,$) are escaped so they display literally, and control characters are shown as Unicode control pictures (e.g.␊).nplus 8 hex characters of a SHA-256 hash of the full target, with only colliding IDs lengthened. Unlike--dot, same-named tables in different databases stay separate nodes.--output-*filters. Stdout and the exit code are unaffected.cli/mermaid.ts, socli/console.tsstays focused on console I/O.mermaidcode fence, the size limits, watch-mode output and a filtered example.Like
--dot, the output doesn't include notebooks, data preparations or property graphs. Styles, subgraphs and theming are left for follow-ups.Why hashed IDs
Mermaid renderers limit diagram size (GitHub refuses diagrams over 50,000 characters), and every edge repeats two IDs. With readable IDs derived from the target name, a 300-table chain came to 73,375 characters; with hashed IDs it's 24,883. For that benchmark, the 500-edge default becomes the limit first, though very long labels can still hit the character limit. Readable IDs could be added later as an opt-in; hashed would stay the default so committed diagrams don't change.
Example
Testing
cli/mermaid_test.tscover output, ordering, labels (including targets without a database, and graphs that only set the string tabletype), escaping, IDs (including a real 8-character hash collision) and the size warning's exact boundaries. New CLI tests cover filtering, flag conflicts and the warning (stderr only, exit code 0).scripts/lintand the full unit suite (scripts/run_tests) pass.end, Unicode and spaces, newlines and tabs, and labels containing#quot;,<br>, backticks,\n,fa:fa-userand$$x+1$$. Special characters displayed literally, and control characters as control pictures.🤖 Generated with Claude Code