7 unstable releases
0.4.0 | Nov 25, 2021 |
---|---|
0.3.0 | Mar 19, 2020 |
0.2.3 | Jun 28, 2019 |
0.2.2 | Jul 24, 2018 |
0.1.0 | Feb 5, 2018 |
#565 in Parser implementations
904,098 downloads per month
Used in 195 crates
(32 directly)
120KB
3.5K
SLoC
GraphQL Parser
Documentation | Github | Crate
A parser, formatter and AST for graphql query and schema definition language for rust.
Supported extensions:
- Subscriptions
- Block (triple quoted) strings
License
Licensed under either of
- Apache License, Version 2.0, (./LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (./LICENSE-MIT or http://opensource.org/licenses/MIT) at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
lib.rs
:
Graphql Parser
This library contains full parser and formatter of the graphql query language as well as AST types.
Current this library supports full graphql syntax, and the following extensions:
- Subscriptions
- Block (triple quoted) strings
- Schema definition language a/k/a IDL (which is still in RFC)
Example: Parse and Format Query
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
}
");
Example: Parse and Format Schema
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!
}
");
Dependencies
~1.1–1.8MB
~38K SLoC