gurkle_parser/
lib.rs

1//! Graphql Parser
2//! ==============
3//!
4//! This library contains full parser and formatter of the graphql
5//! query language as well as AST types.
6//!
7//! [Docs](https://docs.rs/graphql-parser/) |
8//! [Github](https://github.com/graphql-rust/graphql-parser/) |
9//! [Crate](https://crates.io/crates/graphql-parser)
10//!
11//! Current this library supports full graphql syntax, and the following
12//! extensions:
13//!
14//! 1. Subscriptions
15//! 2. Block (triple quoted) strings
16//! 3. Schema definition language a/k/a IDL (which is still in RFC)
17//!
18//!
19//! Example: Parse and Format Query
20//! -------------------------------
21//!
22//! ```rust
23//! use gurkle_parser::query::{parse_query, ParseError};
24//!
25//! # fn parse() -> Result<(), Box<dyn std::error::Error>> {
26//! let ast = parse_query("query MyQuery { field1, field2 }")?;
27//! // Format canonical representation
28//! assert_eq!(format!("{}", ast), "\
29//! query MyQuery {
30//!   field1
31//!   field2
32//! }
33//! ");
34//! # Ok(())
35//! # }
36//! # fn main() {
37//! #    parse().unwrap()
38//! # }
39//! ```
40//!
41//! Example: Parse and Format Schema
42//! --------------------------------
43//!
44//! ```rust
45//! use gurkle_parser::schema::{parse_schema, ParseError};
46//!
47//! # fn parse() -> Result<(), Box<dyn std::error::Error>> {
48//! let ast = parse_schema(r#"
49//!     schema {
50//!         query: Query
51//!     }
52//!     type Query {
53//!         users: [User!]!,
54//!     }
55//!     """
56//!        Example user object
57//!
58//!        This is just a demo comment.
59//!     """
60//!     type User {
61//!         name: String!,
62//!     }
63//! "#)?;
64//! // Format canonical representation
65//! assert_eq!(format!("{}", ast), "\
66//! schema {
67//!   query: Query
68//! }
69//!
70//! type Query {
71//!   users: [User!]!
72//! }
73//!
74//! \"\"\"
75//!   Example user object
76//!
77//!   This is just a demo comment.
78//! \"\"\"
79//! type User {
80//!   name: String!
81//! }
82//! ");
83//! # Ok(())
84//! # }
85//! # fn main() {
86//! #    parse().unwrap()
87//! # }
88//! ```
89//!
90#![warn(missing_debug_implementations)]
91
92#[cfg(test)]
93#[macro_use]
94extern crate pretty_assertions;
95
96mod common;
97#[macro_use]
98mod format;
99mod helpers;
100mod position;
101pub mod query;
102pub mod schema;
103mod tokenizer;
104
105pub use crate::format::Style;
106pub use crate::position::Pos;
107pub use crate::query::parse_query;
108pub use crate::schema::parse_schema;