#graphql #graphql-schema #query-language #parser #schema-definition #ast #serialization

graphql-parser

用于 GraphQL 查询语言和模式定义语言(有时称为 IDL)的解析器、AST 和序列化器。

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解析器实现

Download history 100732/week @ 2024-03-14 98043/week @ 2024-03-21 99821/week @ 2024-03-28 96915/week @ 2024-04-04 109345/week @ 2024-04-11 102676/week @ 2024-04-18 100217/week @ 2024-04-25 103620/week @ 2024-05-02 108757/week @ 2024-05-09 118022/week @ 2024-05-16 126107/week @ 2024-05-23 135749/week @ 2024-05-30 134393/week @ 2024-06-06 124035/week @ 2024-06-13 111578/week @ 2024-06-20 108886/week @ 2024-06-27

510,129 每月下载次数
185 包(32 个直接)中使用

MIT/Apache

120KB
3.5K SLoC

GraphQL 解析器

文档 | Github | Crate

为 Rust 提供的 GraphQL 查询和模式定义语言的解析器、格式化器和 AST。

支持扩展

  1. 订阅
  2. 块(三引号)字符串

许可证

根据您的选择,受以下任一许可证的许可:

贡献

除非您明确声明,否则根据 Apache-2.0 许可证定义的,您有意提交的任何贡献,均应按上述方式双重许可,而不附加任何额外条款或条件。


lib.rs:

Graphql 解析器

此库包含 GraphQL 查询语言的完整解析器和格式化器,以及 AST 类型。

文档 | Github | Crate

当前此库支持完整的 GraphQL 语法和以下扩展:

  1. 订阅
  2. 块(三引号)字符串
  3. 模式定义语言,也称为 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