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

graphql-parser

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

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

#601 in Parser implementations

Download history 72062/week @ 2023-12-07 64706/week @ 2023-12-14 35927/week @ 2023-12-21 42654/week @ 2023-12-28 78010/week @ 2024-01-04 79853/week @ 2024-01-11 114281/week @ 2024-01-18 123411/week @ 2024-01-25 140538/week @ 2024-02-01 131026/week @ 2024-02-08 133043/week @ 2024-02-15 140478/week @ 2024-02-22 136012/week @ 2024-02-29 93501/week @ 2024-03-07 100732/week @ 2024-03-14 78456/week @ 2024-03-21

433,960 downloads per month
Used in 188 crates (32 directly)

MIT/Apache

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:

  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

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.3–2MB
~40K SLoC