#graphql-schema #graphql #query-language #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

#565 in Parser implementations

Download history 125659/week @ 2024-07-26 116537/week @ 2024-08-02 140216/week @ 2024-08-09 161402/week @ 2024-08-16 143744/week @ 2024-08-23 131796/week @ 2024-08-30 165596/week @ 2024-09-06 156247/week @ 2024-09-13 190008/week @ 2024-09-20 167580/week @ 2024-09-27 211568/week @ 2024-10-04 184502/week @ 2024-10-11 208336/week @ 2024-10-18 237230/week @ 2024-10-25 198381/week @ 2024-11-01 220860/week @ 2024-11-08

904,098 downloads per month
Used in 195 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.1–1.8MB
~38K SLoC