libgraphql_parser/ast/null_value.rs
1use crate::ast::ast_node::append_span_source_slice;
2use crate::ast::AstNode;
3use crate::ByteSpan;
4use crate::SourceMap;
5use crate::SourceSpan;
6use crate::token::GraphQLToken;
7use inherent::inherent;
8
9/// A GraphQL null literal.
10///
11/// See the
12/// [Null Value](https://spec.graphql.org/September2025/#sec-Null-Value)
13/// section of the spec.
14#[derive(Clone, Debug, PartialEq)]
15pub struct NullValue<'src> {
16 pub span: ByteSpan,
17 pub syntax: Option<Box<NullValueSyntax<'src>>>,
18}
19
20/// Syntax detail for a [`NullValue`].
21#[derive(Clone, Debug, PartialEq)]
22pub struct NullValueSyntax<'src> {
23 pub token: GraphQLToken<'src>,
24}
25
26#[inherent]
27impl AstNode for NullValue<'_> {
28 /// See [`AstNode::append_source()`](crate::ast::AstNode::append_source).
29 pub fn append_source(
30 &self,
31 sink: &mut String,
32 source: Option<&str>,
33 ) {
34 if let Some(src) = source {
35 append_span_source_slice(
36 self.span, sink, src,
37 );
38 }
39 }
40
41 /// Returns this null value's byte-offset span within the
42 /// source text.
43 ///
44 /// The returned [`ByteSpan`] can be resolved to line/column
45 /// positions via [`source_span()`](Self::source_span) or
46 /// [`ByteSpan::resolve()`].
47 #[inline]
48 pub fn byte_span(&self) -> ByteSpan {
49 self.span
50 }
51
52 /// Resolves this null value's position to line/column
53 /// coordinates using the given [`SourceMap`].
54 ///
55 /// Returns [`None`] if the byte offsets cannot be resolved
56 /// (e.g. the span was synthetically constructed without
57 /// valid position data).
58 #[inline]
59 pub fn source_span(
60 &self,
61 source_map: &SourceMap,
62 ) -> Option<SourceSpan> {
63 self.byte_span().resolve(source_map)
64 }
65}