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