bluejay_core/executable/
operation_definition.rs1use crate::executable::{SelectionSet, VariableDefinitions};
2use crate::{Indexable, OperationType, VariableDirectives};
3
4#[derive(Debug)]
5pub enum OperationDefinitionReference<'a, O: OperationDefinition> {
6 Explicit(&'a O::ExplicitOperationDefinition),
7 Implicit(&'a O::ImplicitOperationDefinition),
8}
9
10impl<'a, O: OperationDefinition> OperationDefinitionReference<'a, O> {
11 pub fn operation_type(&self) -> OperationType {
12 match self {
13 Self::Explicit(eod) => eod.operation_type(),
14 Self::Implicit(_) => OperationType::Query,
15 }
16 }
17
18 pub fn description(&self) -> Option<&str> {
19 match self {
20 Self::Explicit(eod) => eod.description(),
21 Self::Implicit(_) => None,
22 }
23 }
24
25 pub fn name(&self) -> Option<&'a str> {
26 match self {
27 Self::Explicit(eod) => eod.name(),
28 Self::Implicit(_) => None,
29 }
30 }
31
32 pub fn variable_definitions(&self) -> Option<&'a <<O as OperationDefinition>::ExplicitOperationDefinition as ExplicitOperationDefinition>::VariableDefinitions>{
33 match self {
34 Self::Explicit(eod) => eod.variable_definitions(),
35 Self::Implicit(_) => None,
36 }
37 }
38
39 pub fn selection_set(&self) -> &'a <<O as OperationDefinition>::ExplicitOperationDefinition as ExplicitOperationDefinition>::SelectionSet{
40 match self {
41 Self::Explicit(eod) => eod.selection_set(),
42 Self::Implicit(iod) => iod.selection_set(),
43 }
44 }
45
46 pub fn directives(&self) -> Option<&'a <<O as OperationDefinition>::ExplicitOperationDefinition as ExplicitOperationDefinition>::Directives>{
47 match self {
48 Self::Explicit(eod) => eod.directives(),
49 Self::Implicit(_) => None,
50 }
51 }
52}
53
54pub trait OperationDefinition: Sized + Indexable {
55 type ExplicitOperationDefinition: ExplicitOperationDefinition;
56 type ImplicitOperationDefinition: ImplicitOperationDefinition<SelectionSet=<Self::ExplicitOperationDefinition as ExplicitOperationDefinition>::SelectionSet>;
57
58 fn as_ref(&self) -> OperationDefinitionReference<'_, Self>;
59}
60
61pub trait ExplicitOperationDefinition {
62 type VariableDefinitions: VariableDefinitions;
63 type Directives: VariableDirectives;
64 type SelectionSet: SelectionSet;
65
66 fn description(&self) -> Option<&str>;
67 fn operation_type(&self) -> OperationType;
68 fn name(&self) -> Option<&str>;
69 fn variable_definitions(&self) -> Option<&Self::VariableDefinitions>;
70 fn directives(&self) -> Option<&Self::Directives>;
71 fn selection_set(&self) -> &Self::SelectionSet;
72}
73
74pub trait ImplicitOperationDefinition {
75 type SelectionSet: SelectionSet;
76
77 fn selection_set(&self) -> &Self::SelectionSet;
78}