Struct apollo_compiler::Parser
source · pub struct Parser { /* private fields */ }
Expand description
Configuration for parsing an input string as GraphQL syntax
Implementations§
source§impl Parser
impl Parser
pub fn new() -> Self
sourcepub fn recursion_limit(self, value: usize) -> Self
pub fn recursion_limit(self, value: usize) -> Self
Configure the recursion to use while parsing.
sourcepub fn token_limit(self, value: usize) -> Self
pub fn token_limit(self, value: usize) -> Self
Configure the limit on the number of tokens to parse. If an input document is too big, parsing will be aborted. By default, there is no limit.
sourcepub fn parse_ast(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>
) -> Document
pub fn parse_ast( &mut self, source_text: impl Into<String>, path: impl AsRef<Path> ) -> Document
Parse the given source text into an AST document.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Parsing is fault-tolerant, so a document is always returned.
In case of a parse error, Document::check_parse_errors
will return relevant information
and some nodes may be missing in the built document.
sourcepub fn parse_schema(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>
) -> Schema
pub fn parse_schema( &mut self, source_text: impl Into<String>, path: impl AsRef<Path> ) -> Schema
Parse the given source text as the sole input file of a schema.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
To have multiple files contribute to a schema,
use Schema::builder
and Parser::parse_into_schema_builder
.
Parsing is fault-tolerant, so a schema is always returned. TODO: document how to validate
sourcepub fn parse_into_schema_builder(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>,
builder: &mut SchemaBuilder
)
pub fn parse_into_schema_builder( &mut self, source_text: impl Into<String>, path: impl AsRef<Path>, builder: &mut SchemaBuilder )
Parse the given source text as an additional input to a schema builder.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
This can be used to build a schema from multiple source files.
Parsing is fault-tolerant, so this is infallible. TODO: document how to validate.
sourcepub fn parse_executable(
&mut self,
schema: &Schema,
source_text: impl Into<String>,
path: impl AsRef<Path>
) -> ExecutableDocument
pub fn parse_executable( &mut self, schema: &Schema, source_text: impl Into<String>, path: impl AsRef<Path> ) -> ExecutableDocument
Parse the given source text into an executable document, with the given schema.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Parsing is fault-tolerant, so a document is always returned. TODO: document how to validate
sourcepub fn parse_mixed(
&mut self,
source_text: impl Into<String>,
path: impl AsRef<Path>
) -> (Schema, ExecutableDocument)
pub fn parse_mixed( &mut self, source_text: impl Into<String>, path: impl AsRef<Path> ) -> (Schema, ExecutableDocument)
Parse a schema and executable document from the given source text containing a mixture of type system definitions and executable definitions. This is mostly useful for unit tests.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Parsing is fault-tolerant, so a schema and document are always returned. TODO: document how to validate
sourcepub fn parse_field_set(
&mut self,
schema: &Schema,
type_name: impl Into<NamedType>,
source_text: impl Into<String>,
path: impl AsRef<Path>
) -> FieldSet
pub fn parse_field_set( &mut self, schema: &Schema, type_name: impl Into<NamedType>, source_text: impl Into<String>, path: impl AsRef<Path> ) -> FieldSet
Parse the given source a selection set with optional outer brackets.
path
is the filesystem path (or arbitrary string) used in diagnostics
to identify this source file to users.
Parsing is fault-tolerant, so a selection set node is always returned. TODO: document how to validate
sourcepub fn recursion_reached(&self) -> usize
pub fn recursion_reached(&self) -> usize
What level of recursion was reached during the last call to a parse_*
method.
Collecting this on a corpus of documents can help decide
how to set recursion_limit
.
sourcepub fn tokens_reached(&self) -> usize
pub fn tokens_reached(&self) -> usize
How many tokens were created during the last call to a parse_*
method.
Collecting this on a corpus of documents can help decide
how to set recursion_limit
.