pub struct SyntaxTree { /* private fields */ }
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);

Implementations§

Get a reference to the syntax tree’s errors.

Get the syntax tree’s recursion limit.

Return the root typed Document node.

Trait Implementations§

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.