7 个不稳定版本
0.4.0 | 2021年11月25日 |
---|---|
0.3.0 | 2020年3月19日 |
0.2.3 | 2019年6月28日 |
0.2.2 | 2018年7月24日 |
0.1.0 | 2018年2月5日 |
#311 在 解析器实现
510,129 每月下载次数
在 185 个 包(32 个直接)中使用
120KB
3.5K SLoC
GraphQL 解析器
为 Rust 提供的 GraphQL 查询和模式定义语言的解析器、格式化器和 AST。
支持扩展
- 订阅
- 块(三引号)字符串
许可证
根据您的选择,受以下任一许可证的许可:
- Apache 许可证2.0版(./LICENSE-APACHE 或 https://apache.ac.cn/licenses/LICENSE-2.0)
- MIT 许可证(./LICENSE-MIT 或 http://opensource.org/licenses/MIT)
贡献
除非您明确声明,否则根据 Apache-2.0 许可证定义的,您有意提交的任何贡献,均应按上述方式双重许可,而不附加任何额外条款或条件。
lib.rs
:
Graphql 解析器
此库包含 GraphQL 查询语言的完整解析器和格式化器,以及 AST 类型。
当前此库支持完整的 GraphQL 语法和以下扩展:
- 订阅
- 块(三引号)字符串
- 模式定义语言,也称为 IDL(仍在 RFC 中)
示例:解析和格式化查询
use graphql_parser::query::{parse_query, ParseError};
let ast = parse_query::<&str>("query MyQuery { field1, field2 }")?;
// Format canonical representation
assert_eq!(format!("{}", ast), "\
query MyQuery {
field1
field2
}
");
示例:解析和格式化模式
use graphql_parser::schema::{parse_schema, ParseError};
let ast = parse_schema::<String>(r#"
schema {
query: Query
}
type Query {
users: [User!]!,
}
"""
Example user object
This is just a demo comment.
"""
type User {
name: String!,
}
"#)?.to_owned();
// Format canonical representation
assert_eq!(format!("{}", ast), "\
schema {
query: Query
}
type Query {
users: [User!]!
}
\"\"\"
Example user object
This is just a demo comment.
\"\"\"
type User {
name: String!
}
");
依赖项
~1.2–1.9MB
~40K SLoC