graphql_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//! # extern crate graphql_parser;
24//! use graphql_parser::query::{parse_query, ParseError};
25//!
26//! # fn parse() -> Result<(), ParseError> {
27//! let ast = parse_query::<&str>("query MyQuery { field1, field2 }")?;
28//! // Format canonical representation
29//! assert_eq!(format!("{}", ast), "\
30//! query MyQuery {
31//!   field1
32//!   field2
33//! }
34//! ");
35//! # Ok(())
36//! # }
37//! # fn main() {
38//! #    parse().unwrap()
39//! # }
40//! ```
41//!
42//! Example: Parse and Format Schema
43//! --------------------------------
44//!
45//! ```rust
46//! # extern crate graphql_parser;
47//! use graphql_parser::schema::{parse_schema, ParseError};
48//!
49//! # fn parse() -> Result<(), ParseError> {
50//! let ast = parse_schema::<String>(r#"
51//!     schema {
52//!         query: Query
53//!     }
54//!     type Query {
55//!         users: [User!]!,
56//!     }
57//!     """
58//!        Example user object
59//!
60//!        This is just a demo comment.
61//!     """
62//!     type User {
63//!         name: String!,
64//!     }
65//! "#)?.to_owned();
66//! // Format canonical representation
67//! assert_eq!(format!("{}", ast), "\
68//! schema {
69//!   query: Query
70//! }
71//!
72//! type Query {
73//!   users: [User!]!
74//! }
75//!
76//! \"\"\"
77//!   Example user object
78//!
79//!   This is just a demo comment.
80//! \"\"\"
81//! type User {
82//!   name: String!
83//! }
84//! ");
85//! # Ok(())
86//! # }
87//! # fn main() {
88//! #    parse().unwrap()
89//! # }
90//! ```
91//!
92#![warn(missing_debug_implementations)]
93
94#[cfg(test)] #[macro_use] extern crate pretty_assertions;
95
96
97mod common;
98#[macro_use]
99mod format;
100mod position;
101mod tokenizer;
102mod helpers;
103pub mod query;
104pub mod schema;
105
106pub use crate::query::parse_query;
107pub use crate::schema::parse_schema;
108pub use crate::query::minify_query;
109pub use crate::position::Pos;
110pub use crate::format::Style;