Skip to main content

GraphQLParser

Struct GraphQLParser 

Source
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>>

Source

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>

Source

pub fn from_token_source(token_source: TTokenSource) -> Self

Creates a new parser from a token source.

Source

pub fn parse_schema_document(self) -> ParseResult<Document>

Parses a schema document (type system definitions only).

Source

pub fn parse_executable_document(self) -> ParseResult<Document>

Parses an executable document (operations and fragments only).

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.