GraphQL 格式化工具
使用官方 graphql/language 解析器,美化 GraphQL 的 query、mutation 和 SDL。
正在加载 GraphQL 解析器…
使用方法
- 1 粘贴一段 GraphQL 的 query、mutation、subscription 或 SDL。
- 2 点击「美化」,工具会使用官方 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">graphql/language</code> 打印器(printer)重新格式化代码。
- 3 点击「压缩」可去除空白和注释,得到更精简的传输格式。
- 4 如遇解析错误,会显示对应的行号和列号。
为什么使用此工具
- 基于 <code class="rounded bg-slate-100 px-1 text-xs dark:bg-slate-800">graphql/language</code> 官方的 parse 和 print 函数——输出为标准(canonical)SDL。
- 按需加载——只有在你开始输入内容时才会下载解析器。
- 支持双向转换——美化便于存入代码仓库,压缩便于网络传输。
- 完全在客户端处理——你的 query 内容不会离开浏览器。
常见问题
这个工具支持 GraphQL SDL(schema)吗?
支持——SDL(Schema Definition Language)会通过相同的机制被解析和打印。你可以用它来格式化整个 schema,包括 types、directives 和 unions。
为什么第一次格式化需要一点时间?
GraphQL 解析库会在你首次输入内容时才被懒加载(lazy load)。之后的格式化操作会即时完成。
Fragments 和 variables 的顺序会被重新排列吗?
不会——打印器会保留你原本的声明顺序,只会调整空白和逗号的排布方式。
什么是 GraphQL 格式化工具?
GraphQL Formatter(GraphQL 格式化工具)使用官方 graphql/language 解析器,对 GraphQL 的 query、mutation 以及 schema definition language(SDL)进行美化排版。工具会先解析输入内容,再以统一的缩进和空白重新生成代码,让 GraphQL 文档在浏览器中即可变得结构清晰、易于阅读。
功能特性
AST-based printing
Parses with graphql-js and re-prints from the AST, so output is always syntactically valid.
Queries, mutations & SDL
Formats operations and type definitions alike, including fragments and directives.
100% private
Your GraphQL is parsed on the device and never uploaded.
示例
Input
{ user(id:1){name posts{title}} }
Output
{
user(id: 1) {
name
posts {
title
}
}
}
常见使用场景
-
1
Tidy a copied query
Reformat a one-line or messy GraphQL query into a readable, indented form.
-
2
Clean up SDL
Normalize a schema file's spacing before committing or reviewing.
-
3
Validate while formatting
A parse error pinpoints a syntax mistake before you send the query.
Zerethon's GraphQL formatter pretty-prints queries, mutations, and schema definition language (SDL) using the official graphql-js parser. It parses the document into an AST and re-serializes it with consistent two-space indentation and spacing, so malformed input surfaces as a parse error rather than silently reformatting. Everything runs in your browser.
- 分类
- 开发者
- 价格
- 免费
- 隐私
- 基于浏览器
- 注册
- 无需
References
- GraphQL Specification — GraphQL Foundation
- graphql-js — reference implementation — GitHub
隐私
除非另有说明,否则你的数据永远不会离开浏览器。GraphQL 格式化工具 完全在客户端运行 — 无需上传服务器,不记录日志,不追踪你输入的内容。
相关工具
在 Zerethon Social 上创作、分享与成长
免费注册。赚取积分,收集成就,与全球创作者建立联系。