libgraphql_parser/ast/
input_value_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 InputValueDefinition<'src> {
22 pub default_value: Option<Value<'src>>,
23 pub description: Option<StringValue<'src>>,
24 pub directives: Vec<DirectiveAnnotation<'src>>,
25 pub name: Name<'src>,
26 pub span: ByteSpan,
27 pub syntax: Option<Box<InputValueDefinitionSyntax<'src>>>,
28 pub value_type: TypeAnnotation<'src>,
29}
30
31#[derive(Clone, Debug, PartialEq)]
33pub struct InputValueDefinitionSyntax<'src> {
34 pub colon: GraphQLToken<'src>,
35 pub equals: Option<GraphQLToken<'src>>,
36}
37
38impl<'src> InputValueDefinition<'src> {
39 #[inline]
44 pub fn name_value(&self) -> &str {
45 self.name.value.as_ref()
46 }
47}
48
49#[inherent]
50impl AstNode for InputValueDefinition<'_> {
51 pub fn append_source(
53 &self,
54 sink: &mut String,
55 source: Option<&str>,
56 ) {
57 if let Some(src) = source {
58 append_span_source_slice(
59 self.span, sink, src,
60 );
61 }
62 }
63
64 #[inline]
71 pub fn byte_span(&self) -> ByteSpan {
72 self.span
73 }
74
75 #[inline]
82 pub fn source_span(
83 &self,
84 source_map: &SourceMap,
85 ) -> Option<SourceSpan> {
86 self.byte_span().resolve(source_map)
87 }
88}