Graphql Parser
This library contains full parser and formatter of the graphql
query language as well as AST types.
Docs |
Github |
Crate
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 gurkle_parser::query::{parse_query, ParseError};
# fn parse() -> Result<(), Box<dyn std::error::Error>> {
let ast = parse_query("query MyQuery { field1, field2 }")?;
assert_eq!(format!("{}", ast), "\
query MyQuery {
field1
field2
}
");
# Ok(())
# }
# fn main() {
# parse().unwrap()
# }
Example: Parse and Format Schema
use gurkle_parser::schema::{parse_schema, ParseError};
# fn parse() -> Result<(), Box<dyn std::error::Error>> {
let ast = parse_schema(r#"
schema {
query: Query
}
type Query {
users: [User!]!,
}
"""
Example user object
This is just a demo comment.
"""
type User {
name: String!,
}
"#)?;
assert_eq!(format!("{}", ast), "\
schema {
query: Query
}
type Query {
users: [User!]!
}
\"\"\"
Example user object
This is just a demo comment.
\"\"\"
type User {
name: String!
}
");
# Ok(())
# }
# fn main() {
# parse().unwrap()
# }