libgraphql_parser/ast/
fragment_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::SelectionSet;
6use crate::ast::StringValue;
7use crate::ast::TypeCondition;
8use crate::ByteSpan;
9use crate::SourceMap;
10use crate::SourceSpan;
11use crate::token::GraphQLToken;
12use inherent::inherent;
13
14#[derive(Clone, Debug, PartialEq)]
20pub struct FragmentDefinition<'src> {
21 pub description: Option<StringValue<'src>>,
22 pub directives: Vec<DirectiveAnnotation<'src>>,
23 pub name: Name<'src>,
24 pub selection_set: SelectionSet<'src>,
25 pub span: ByteSpan,
26 pub syntax:
27 Option<Box<FragmentDefinitionSyntax<'src>>>,
28 pub type_condition: TypeCondition<'src>,
29}
30
31#[derive(Clone, Debug, PartialEq)]
37pub struct FragmentDefinitionSyntax<'src> {
38 pub fragment_keyword: GraphQLToken<'src>,
39}
40
41impl<'src> FragmentDefinition<'src> {
42 #[inline]
47 pub fn name_value(&self) -> &str {
48 self.name.value.as_ref()
49 }
50}
51
52#[inherent]
53impl AstNode for FragmentDefinition<'_> {
54 pub fn append_source(
56 &self,
57 sink: &mut String,
58 source: Option<&str>,
59 ) {
60 if let Some(src) = source {
61 append_span_source_slice(
62 self.span, sink, src,
63 );
64 }
65 }
66
67 #[inline]
74 pub fn byte_span(&self) -> ByteSpan {
75 self.span
76 }
77
78 #[inline]
85 pub fn source_span(
86 &self,
87 source_map: &SourceMap,
88 ) -> Option<SourceSpan> {
89 self.byte_span().resolve(source_map)
90 }
91}