#graphql #parser

graphql-parser

A parser, AST and serializer for graphql query language and scheme definition language (sometimes called IDL)

4 releases

0.2.2 Jul 24, 2018
0.2.1 Jun 4, 2018
0.2.0 Feb 11, 2018
0.1.0 Feb 5, 2018

#28 in Parser implementations

Download history 227/week @ 2018-09-08 211/week @ 2018-09-15 309/week @ 2018-09-22 272/week @ 2018-09-29 325/week @ 2018-10-06 346/week @ 2018-10-13 393/week @ 2018-10-20 312/week @ 2018-10-27 307/week @ 2018-11-03 283/week @ 2018-11-10 462/week @ 2018-11-17 363/week @ 2018-11-24 297/week @ 2018-12-01

393 downloads per month
Used in 9 crates (6 directly)

MIT/Apache

100KB
3K SLoC

GraphQL Parser

Documentation | Github | Crate

A parser, formatter and AST for graphql query and schema definition language for rust.

Supported extensions:

  1. Subscriptions
  2. Block (triple quoted) strings

License

Licensed under either of

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.

Docs | Github | Crate

Current this library supports full graphql syntax, and the following extensions:

  1. Subscriptions
  2. Block (triple quoted) strings
  3. Schema definition language a/k/a IDL (which is still in RFC)

Example: Parse and Format Query

# extern crate failure;
# extern crate graphql_parser;
use graphql_parser::parse_query;

# fn parse() -> Result<(), failure::Error> {
let ast = parse_query("query MyQuery { field1, field2 }")?;
// Format canonical representation
assert_eq!(format!("{}", ast), "\
query MyQuery {
  field1
  field2
}
");
# Ok(())
# }
# fn main() {
#    parse().unwrap()
# }

Example: Parse and Format Schema

# extern crate failure;
# extern crate graphql_parser;
use graphql_parser::parse_schema;

# fn parse() -> Result<(), failure::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!,
    }
"#)?;
// 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!
}
");
# Ok(())
# }
# fn main() {
#    parse().unwrap()
# }

Dependencies

~768KB
~16K SLoC