libgraphql_parser/ast/
variable_definition.rs1use crate::ast::ast_node::append_span_source_slice;
2use crate::ast::AstNode;
3use crate::ast::DirectiveAnnotation;
4use crate::ast::Name;
5use crate::ast::StringValue;
6use crate::ast::TypeAnnotation;
7use crate::ast::Value;
8use crate::ByteSpan;
9use crate::SourceMap;
10use crate::SourceSpan;
11use crate::token::GraphQLToken;
12use inherent::inherent;
13
14#[derive(Clone, Debug, PartialEq)]
21pub struct VariableDefinition<'src> {
22 pub default_value: Option<Value<'src>>,
23 pub description: Option<StringValue<'src>>,
24 pub directives: Vec<DirectiveAnnotation<'src>>,
25 pub span: ByteSpan,
26 pub syntax:
27 Option<Box<VariableDefinitionSyntax<'src>>>,
28 pub var_type: TypeAnnotation<'src>,
29 pub variable: Name<'src>,
30}
31
32#[derive(Clone, Debug, PartialEq)]
34pub struct VariableDefinitionSyntax<'src> {
35 pub colon: GraphQLToken<'src>,
36 pub dollar: GraphQLToken<'src>,
37 pub equals: Option<GraphQLToken<'src>>,
38}
39
40#[inherent]
41impl AstNode for VariableDefinition<'_> {
42 pub fn append_source(
44 &self,
45 sink: &mut String,
46 source: Option<&str>,
47 ) {
48 if let Some(src) = source {
49 append_span_source_slice(
50 self.span, sink, src,
51 );
52 }
53 }
54
55 #[inline]
62 pub fn byte_span(&self) -> ByteSpan {
63 self.span
64 }
65
66 #[inline]
73 pub fn source_span(
74 &self,
75 source_map: &SourceMap,
76 ) -> Option<SourceSpan> {
77 self.byte_span().resolve(source_map)
78 }
79}