#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)

8 releases

0.4.1 Dec 3, 2024
0.4.0 Nov 25, 2021
0.3.0 Mar 19, 2020
0.2.3 Jun 28, 2019
0.1.0 Feb 5, 2018

#49 in Parser implementations

Download history 146004/week @ 2024-08-21 131572/week @ 2024-08-28 163775/week @ 2024-09-04 166321/week @ 2024-09-11 166457/week @ 2024-09-18 177115/week @ 2024-09-25 189176/week @ 2024-10-02 199519/week @ 2024-10-09 199522/week @ 2024-10-16 227395/week @ 2024-10-23 206062/week @ 2024-10-30 217625/week @ 2024-11-06 207500/week @ 2024-11-13 193825/week @ 2024-11-20 108299/week @ 2024-11-27 128291/week @ 2024-12-04

677,171 downloads per month
Used in 200 crates (33 directly)

MIT/Apache

130KB
4K 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

~0.8–1.4MB
~31K SLoC