Struct apollo_parser::Parser
source · [−]pub struct Parser { /* private fields */ }
Expand description
Parse GraphQL schemas or queries into a typed AST.
Example
The API to parse a query or a schema is the same, as the parser currently
accepts a &str
. Here is an example of parsing a query:
use apollo_parser::Parser;
let query = "
{
animal
...snackSelection
... on Pet {
playmates {
count
}
}
}
";
// Create a new instance of a parser given a query above.
let parser = Parser::new(query);
// Parse the query, and return a SyntaxTree.
let ast = parser.parse();
// Check that are no errors. These are not part of the AST.
assert_eq!(0, ast.errors().len());
// Get the document root node
let doc = ast.document();
// ... continue
Here is how you’d parse a schema:
use apollo_parser::Parser;
let core_schema = r#"
schema @core(feature: "https://specs.apollo.dev/join/v0.1") {
query: Query
mutation: Mutation
}
enum join__Graph {
ACCOUNTS @join__graph(name: "accounts")
}
"#;
let parser = Parser::new(core_schema);
let ast = parser.parse();
assert_eq!(0, ast.errors().len());
let document = ast.document();
Implementations
sourceimpl Parser
impl Parser
sourcepub fn with_recursion_limit(input: &str, recursion_limit: usize) -> Self
pub fn with_recursion_limit(input: &str, recursion_limit: usize) -> Self
Create a new resource limited instance of a parser given an input string and a recursion limit.
sourcepub fn parse(self) -> SyntaxTree
pub fn parse(self) -> SyntaxTree
Parse the current tokens.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Parser
impl !Send for Parser
impl !Sync for Parser
impl Unpin for Parser
impl !UnwindSafe for Parser
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more