Skip to main content

GraphQLParseErrorKind

Enum GraphQLParseErrorKind 

Source
pub enum GraphQLParseErrorKind {
    UnexpectedToken {
        expected: Vec<String>,
        found: String,
    },
    UnexpectedEof {
        expected: Vec<String>,
    },
    LexerError,
    UnclosedDelimiter {
        delimiter: String,
    },
    MismatchedDelimiter {
        expected: String,
        found: String,
    },
    InvalidValue(ValueParsingError),
    ReservedName {
        name: String,
        context: ReservedNameContext,
    },
    WrongDocumentKind {
        found: DefinitionKind,
        document_kind: DocumentKind,
    },
    InvalidEmptyConstruct {
        construct: String,
    },
    InvalidSyntax,
}
Expand description

Categorizes parse errors for programmatic handling.

Each variant contains minimal data needed for programmatic decisions. Human-readable context (suggestions, explanations) belongs in the notes field of GraphQLParseError.

The #[error(...)] messages are concise/programmatic. Full human-readable messages are in GraphQLParseError.message.

Variants§

§

UnexpectedToken

Expected specific token(s) but found something else.

This is the most common error type — the parser expected certain tokens based on grammar rules but encountered something unexpected.

§Example

type User { name String }
                 ^^^^^^ expected `:`, found `String`

Fields

§expected: Vec<String>

What tokens were expected (e.g., [":"​, "{"​, "@"]).

§found: String

Description of what was found (e.g., "String" or "}").

§

UnexpectedEof

Unexpected end of input while parsing.

The document ended before a complete construct was parsed.

§Example

type User {
          ^ expected `}`, found end of input

Fields

§expected: Vec<String>

What was expected when EOF was encountered.

§

LexerError

Lexer error encountered during parsing.

The parser encountered a GraphQLTokenKind::Error token from the lexer. The lexer’s error message and notes are preserved in the parent GraphQLParseError’s message and notes fields.

§Example

type User { name: "unterminated string
                  ^ unterminated string literal
§

UnclosedDelimiter

Unclosed delimiter (bracket, brace, or parenthesis).

A delimiter was opened but EOF was reached before finding the matching closing delimiter. The opening location is typically included in the error’s notes.

§Example

type User {
    name: String
# EOF here — missing `}`

Note: This is distinct from MismatchedDelimiter, which occurs when a wrong closing delimiter is found (e.g., [ closed with )).

Fields

§delimiter: String

The unclosed delimiter (e.g., "{", "[", "(").

§

MismatchedDelimiter

Mismatched delimiter.

A closing delimiter was found that doesn’t match the most recently opened delimiter. This indicates a structural nesting error.

§Example

type User { name: [String) }
                        ^ expected `]`, found `)`

Note: This is distinct from UnclosedDelimiter, which occurs when EOF is reached without any closing delimiter.

Fields

§expected: String

The expected closing delimiter (e.g., "]").

§found: String

The actual closing delimiter found (e.g., ")").

§

InvalidValue(ValueParsingError)

Invalid value (wraps value parsing errors).

Occurs when a literal value (string, int, float) cannot be parsed.

§Example

query { field(limit: 99999999999999999999) }
                     ^^^^^^^^^^^^^^^^^^^^ integer overflow
§

ReservedName

Reserved name used in a context where it’s not allowed.

Certain names have special meaning in specific contexts:

  • on cannot be a fragment name (it introduces type conditions)
  • true, false, null cannot be enum values (ambiguous with literals)

§Example

fragment on on User { name }
         ^^ fragment name cannot be `on`

Fields

§name: String

The reserved name that was used (e.g., "on", "true").

§context: ReservedNameContext

The context where this name is not allowed.

§

WrongDocumentKind

Definition kind not allowed in the document being parsed.

When parsing with parse_executable_document(), schema definitions (types, directives) are not allowed. When parsing with parse_schema_document(), operations and fragments are not allowed.

§Example

# Parsing as executable document:
type User { name: String }
^^^^ type definition not allowed in executable document

Fields

§found: DefinitionKind

What kind of definition was found.

§document_kind: DocumentKind

What kind of document is being parsed.

§

InvalidEmptyConstruct

Empty construct that requires content.

Certain constructs cannot be empty per the GraphQL spec:

  • Selection sets: { } is invalid (must have at least one selection)
  • Argument lists: () is invalid (omit parentheses if no arguments)

§Example

query { user { } }
             ^^^ selection set cannot be empty

Fields

§construct: String

What construct is empty (e.g., "selection set").

§

InvalidSyntax

Invalid syntax that doesn’t fit other categories.

A catch-all for syntax errors without dedicated variants. The specific error is described in GraphQLParseError.message.

Trait Implementations§

Source§

impl Clone for GraphQLParseErrorKind

Source§

fn clone(&self) -> GraphQLParseErrorKind

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for GraphQLParseErrorKind

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for GraphQLParseErrorKind

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for GraphQLParseErrorKind

1.30.0 · Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0: use the Display impl or to_string()
1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0: replaced by Error::source, which can support downcasting
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more
Source§

impl PartialEq for GraphQLParseErrorKind

Source§

fn eq(&self, other: &GraphQLParseErrorKind) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for GraphQLParseErrorKind

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.