Skip to content

feat: add DQL format button to the query editor#421

Open
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:sp/dql-formatter
Open

feat: add DQL format button to the query editor#421
shaunpatterson wants to merge 1 commit into
dgraph-io:mainfrom
shaunpatterson:sp/dql-formatter

Conversation

@shaunpatterson

Copy link
Copy Markdown
Contributor

What

A Format button next to Clear that pretty-prints the current query via a conservative, whitespace-only DQL formatter (lib/formatDql.js).

in:  {q(func: has(name)){name age friend{name}}}
out: {
       q(func: has(name)) {
         name
         age
         friend {
           name
         }
       }
     }

Formatter guarantees

  • Whitespace-only: never reorders, quotes, or rewrites tokens.
  • Tokenizer respects string literals (with escapes) and # comments — content inside strings is never touched; language tags (name@en:fr) stay merged.
  • 2-space indent, { at line end, } dedented on its own line, one field per line; @filter(...)/arg groups stay attached to their field; as-var blocks and query headers stay on one line.
  • N-Quad bodies inside set { } / delete { } mutation blocks are re-indented but otherwise left raw.
  • Idempotent (format(format(x)) === format(x), tested); unterminated string → input returned unchanged; unbalanced braces degrade gracefully (depth clamped, no error).

Testing

14 unit tests covering all of the above. npm run build passes.

🤖 Generated with Claude Code

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@shaunpatterson shaunpatterson requested a review from a team as a code owner June 12, 2026 17:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant