bluejay_core/definition/
directive_definition.rs

1use crate::definition::ArgumentsDefinition;
2use crate::AsIter;
3use strum::{AsRefStr, Display, EnumIter, EnumString, VariantNames};
4
5#[derive(
6    Debug, Clone, Copy, EnumString, VariantNames, EnumIter, AsRefStr, Display, PartialEq, Eq,
7)]
8#[strum(serialize_all = "SCREAMING_SNAKE_CASE")]
9pub enum DirectiveLocation {
10    Query,
11    Mutation,
12    Subscription,
13    Field,
14    FragmentDefinition,
15    FragmentSpread,
16    InlineFragment,
17    VariableDefinition,
18    Schema,
19    Scalar,
20    Object,
21    FieldDefinition,
22    ArgumentDefinition,
23    Interface,
24    Union,
25    Enum,
26    EnumValue,
27    InputObject,
28    InputFieldDefinition,
29}
30
31impl DirectiveLocation {
32    pub const POSSIBLE_VALUES: &'static [&'static str] = Self::VARIANTS;
33
34    pub fn is_executable(&self) -> bool {
35        matches!(
36            self,
37            Self::Query
38                | Self::Mutation
39                | Self::Subscription
40                | Self::Field
41                | Self::FragmentDefinition
42                | Self::FragmentSpread
43                | Self::InlineFragment
44                | Self::VariableDefinition
45        )
46    }
47}
48
49pub trait DirectiveDefinition {
50    type ArgumentsDefinition: ArgumentsDefinition;
51    type DirectiveLocations: AsIter<Item = DirectiveLocation>;
52
53    fn description(&self) -> Option<&str>;
54    fn name(&self) -> &str;
55    fn arguments_definition(&self) -> Option<&Self::ArgumentsDefinition>;
56    fn is_repeatable(&self) -> bool;
57    fn locations(&self) -> &Self::DirectiveLocations;
58    fn is_builtin(&self) -> bool;
59}