pub struct GraphQLParser<'src, TTokenSource: GraphQLTokenSource<'src>> { /* private fields */ }Expand description
A recursive descent parser for GraphQL documents.
Generic over the token source, enabling parsing from both string input
(StrGraphQLTokenSource) and proc-macro input
(RustMacroGraphQLTokenSource).
§Usage
use libgraphql_parser::ast;
use libgraphql_parser::GraphQLParser;
let source = "type Query { hello: String }";
let parser = GraphQLParser::new(source);
let result = parser.parse_schema_document();
assert!(result.is_ok());
if let Some(doc) = result.valid_ast() {
assert!(matches!(
doc.definitions[0],
ast::schema::Definition::TypeDefinition(_),
));
}Implementations§
Source§impl<'src> GraphQLParser<'src, StrGraphQLTokenSource<'src>>
impl<'src> GraphQLParser<'src, StrGraphQLTokenSource<'src>>
Sourcepub fn new<S: AsRef<str> + ?Sized>(source: &'src S) -> Self
pub fn new<S: AsRef<str> + ?Sized>(source: &'src S) -> Self
Creates a new parser from a string-like source.
Accepts any type that can be referenced as a str,
including &str, &String, and &Cow<str>.
§Example
use libgraphql_parser::GraphQLParser;
let source = "type Query { hello: String }";
let parser = GraphQLParser::new(source);
let result = parser.parse_schema_document();
assert!(result.is_ok());Source§impl<'src, TTokenSource: GraphQLTokenSource<'src>> GraphQLParser<'src, TTokenSource>
impl<'src, TTokenSource: GraphQLTokenSource<'src>> GraphQLParser<'src, TTokenSource>
Sourcepub fn from_token_source(token_source: TTokenSource) -> Self
pub fn from_token_source(token_source: TTokenSource) -> Self
Creates a new parser from a token source.
Sourcepub fn parse_schema_document(self) -> ParseResult<Document>
pub fn parse_schema_document(self) -> ParseResult<Document>
Parses a schema document (type system definitions only).
Sourcepub fn parse_executable_document(self) -> ParseResult<Document>
pub fn parse_executable_document(self) -> ParseResult<Document>
Parses an executable document (operations and fragments only).
Sourcepub fn parse_mixed_document(self) -> ParseResult<MixedDocument>
pub fn parse_mixed_document(self) -> ParseResult<MixedDocument>
Parses a mixed document (both type system and executable definitions).
Auto Trait Implementations§
impl<'src, TTokenSource> Freeze for GraphQLParser<'src, TTokenSource>where
TTokenSource: Freeze,
impl<'src, TTokenSource> RefUnwindSafe for GraphQLParser<'src, TTokenSource>where
TTokenSource: RefUnwindSafe,
impl<'src, TTokenSource> Send for GraphQLParser<'src, TTokenSource>where
TTokenSource: Send,
impl<'src, TTokenSource> Sync for GraphQLParser<'src, TTokenSource>where
TTokenSource: Sync,
impl<'src, TTokenSource> Unpin for GraphQLParser<'src, TTokenSource>where
TTokenSource: Unpin,
impl<'src, TTokenSource> UnwindSafe for GraphQLParser<'src, TTokenSource>where
TTokenSource: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more