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

graphql-parser-hive-fork

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

1 unstable release

new 0.5.0 Nov 12, 2024

#1223 in Parser implementations

Download history 319/week @ 2024-11-09

319 downloads per month
Used in 2 crates

MIT/Apache

130KB
4K SLoC

GraphQL Parser (fork)

This repo is a fork of graphql-rust/graphql-parser with recent changes.

You can follow the original repository, and just replace the dependency name to graphql-parser-hive-fork:

# graphql-parser = "0.4.0"
graphql-parser-hive-fork = "0.5.0"

Documentation | Github | Crate


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.5MB
~32K SLoC