pub struct Document<'src> {
pub definitions: Vec<Definition<'src>>,
pub span: ByteSpan,
pub syntax: Option<Box<DocumentSyntax<'src>>>,
}Expand description
Root AST node for any GraphQL document.
A document contains a list of Definitions which
may be type-system definitions, type-system extensions,
or executable definitions (operations and fragments).
The spec’s
Document
grammar production allows both executable and
type-system definitions to coexist:
Document : Definition+
Definition :
ExecutableDefinition |
TypeSystemDefinitionOrExtensionHowever, more constrained document types exist for
specific use cases:
ExecutableDocument
(operations and fragments only) and
TypeSystemDocument
(type-system definitions only). The spec
mandates
that a document submitted for execution must contain
only executable definitions — but parsing is a separate
concern from execution.
This AST uses a single unified Document type that
can represent any of these document forms. This is
useful because a parser library serves many tools
beyond just execution services: schema linters,
formatters, code generators, IDE language servers, and
document merge/federation tools all benefit from being
able to parse any valid GraphQL syntax without
rejecting it at the parse level. Validation of which
definition kinds are permitted is left to downstream
consumers (e.g. an execution engine rejecting
type-system definitions). The convenience methods
schema_definitions()
and
executable_definitions()
provide easy filtering when needed.
See Document in the spec.
Fields§
§definitions: Vec<Definition<'src>>§span: ByteSpan§syntax: Option<Box<DocumentSyntax<'src>>>Implementations§
Source§impl<'src> Document<'src>
impl<'src> Document<'src>
Sourcepub fn executable_definitions(&self) -> impl Iterator<Item = &Definition<'src>>
pub fn executable_definitions(&self) -> impl Iterator<Item = &Definition<'src>>
Iterate over only the executable definitions (operations and fragments) in this document.
Sourcepub fn schema_definitions(&self) -> impl Iterator<Item = &Definition<'src>>
pub fn schema_definitions(&self) -> impl Iterator<Item = &Definition<'src>>
Iterate over only the type-system definitions and extensions in this document.
Sourcepub fn trailing_trivia(&self) -> Option<&[GraphQLTriviaToken<'src>]>
pub fn trailing_trivia(&self) -> Option<&[GraphQLTriviaToken<'src>]>
Returns the trailing trivia tokens (whitespace, comments) that appear after the last definition in the document, if syntax detail was captured.
Source§impl Document<'_>
impl Document<'_>
Sourcepub fn append_source(&self, sink: &mut String, source: Option<&str>)
pub fn append_source(&self, sink: &mut String, source: Option<&str>)
Sourcepub fn byte_span(&self) -> ByteSpan
pub fn byte_span(&self) -> ByteSpan
Returns this document’s byte-offset span within the source text.
The returned ByteSpan can be resolved to line/column
positions via source_span() or
ByteSpan::resolve().
Sourcepub fn source_span(&self, source_map: &SourceMap<'_>) -> Option<SourceSpan>
pub fn source_span(&self, source_map: &SourceMap<'_>) -> Option<SourceSpan>
Trait Implementations§
Source§impl AstNode for Document<'_>
impl AstNode for Document<'_>
Source§fn byte_span(&self) -> ByteSpan
fn byte_span(&self) -> ByteSpan
Returns this document’s byte-offset span within the source text.
The returned ByteSpan can be resolved to line/column
positions via source_span() or
ByteSpan::resolve().