1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
use crate::ast::executable::{SelectionSet, TypeCondition};
use crate::ast::{FromTokens, IsMatch, ParseError, Tokens, VariableDirectives};
use crate::lexical_token::Name;
use crate::HasSpan;
#[derive(Debug)]
pub struct FragmentDefinition<'a> {
name: Name<'a>,
type_condition: TypeCondition<'a>,
directives: VariableDirectives<'a>,
selection_set: SelectionSet<'a>,
}
impl<'a> IsMatch<'a> for FragmentDefinition<'a> {
fn is_match(tokens: &mut impl Tokens<'a>) -> bool {
tokens.peek_name_matches(0, "fragment")
}
}
impl<'a> FromTokens<'a> for FragmentDefinition<'a> {
fn from_tokens(tokens: &mut impl Tokens<'a>) -> Result<Self, ParseError> {
tokens.expect_name_value("fragment")?;
let name = tokens.expect_name()?;
if name.as_ref() == TypeCondition::ON {
return Err(ParseError::UnexpectedToken { span: name.span() });
}
let type_condition = TypeCondition::from_tokens(tokens)?;
let directives = VariableDirectives::from_tokens(tokens)?;
let selection_set = SelectionSet::from_tokens(tokens)?;
Ok(Self {
name,
type_condition,
directives,
selection_set,
})
}
}
impl<'a> FragmentDefinition<'a> {
pub fn name(&self) -> &str {
self.name.as_ref()
}
pub fn type_condition(&self) -> &str {
self.type_condition.named_type().as_ref()
}
pub fn selection_set(&self) -> &SelectionSet {
&self.selection_set
}
}
impl<'a> bluejay_core::executable::FragmentDefinition for FragmentDefinition<'a> {
type Directives = VariableDirectives<'a>;
type SelectionSet = SelectionSet<'a>;
fn name(&self) -> &str {
self.name.as_ref()
}
fn type_condition(&self) -> &str {
self.type_condition.named_type().as_ref()
}
fn directives(&self) -> &Self::Directives {
&self.directives
}
fn selection_set(&self) -> &Self::SelectionSet {
&self.selection_set
}
}