Struct apollo_parser::SyntaxTree [−][src]
pub struct SyntaxTree { /* fields omitted */ }
Expand description
An AST generated by the parser. Consists of a syntax tree and a Vec<Error>
if any.
Example
Given a syntactically incorrect token uasdf21230jkdw
which cannot be part
of any of GraphQL definitions and a syntactically correct SelectionSet, we
are able to see both the AST for the SelectionSet and the error with an
incorrect token.
use apollo_parser::Parser;
let schema = r#"
uasdf21230jkdw
{
pet
faveSnack
}
"#;
let parser = Parser::new(schema);
let ast = parser.parse();
// The Vec<Error> that's part of the SyntaxTree struct.
assert_eq!(ast.errors().len(), 1);
// The AST with Document as its root node.
let doc = ast.document();
let nodes: Vec<_> = doc.definitions().into_iter().collect();
assert_eq!(nodes.len(), 1);