//! A parser for GraphQL. Used in the [`async-graphql`](https://crates.io/crates/async-graphql) //! crate. //! //! It uses the [pest](https://crates.io/crates/pest) crate to parse the input and then transforms //! it into Rust types. #![forbid(unsafe_code)] use pest::error::LineColLocation; use pest::RuleType; use std::fmt; pub use parser::parse_query; pub use pos::{Pos, Positioned}; pub mod types; mod parser; mod pos; mod utils; /// Parser error. #[derive(Debug, PartialEq)] pub struct Error { /// The position at which the error occurred. pub pos: Pos, /// The error message. pub message: String, } impl fmt::Display for Error { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.write_str(&self.message) } } impl std::error::Error for Error {} impl From> for Error { fn from(err: pest::error::Error) -> Self { Error { pos: { match err.line_col { LineColLocation::Pos((line, column)) | LineColLocation::Span((line, column), _) => Pos { line, column }, } }, message: err.to_string(), } } } /// An alias for `Result`. pub type Result = std::result::Result;