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
use crate::executable::{Field, FragmentSpread, InlineFragment};

#[derive(Debug)]
pub enum SelectionReference<'a, S: Selection> {
    Field(&'a S::Field),
    FragmentSpread(&'a S::FragmentSpread),
    InlineFragment(&'a S::InlineFragment),
}

pub trait Selection: Sized {
    type Field: Field;
    type FragmentSpread: FragmentSpread<Directives = <Self::Field as Field>::Directives>;
    type InlineFragment: InlineFragment<Directives = <Self::Field as Field>::Directives>;

    fn as_ref(&self) -> SelectionReference<'_, Self>;
}

impl<'a, S: Selection> SelectionReference<'a, S> {
    pub fn directives(&self) -> &'a <S::Field as Field>::Directives {
        match self {
            Self::Field(f) => f.directives(),
            Self::FragmentSpread(fs) => fs.directives(),
            Self::InlineFragment(i) => i.directives(),
        }
    }
}