bluejay_validator/executable/document/
visitor.rs

1use crate::executable::{document::Path, Cache};
2use bluejay_core::definition::{DirectiveLocation, SchemaDefinition, TypeDefinitionReference};
3use bluejay_core::executable::ExecutableDocument;
4
5pub trait Visitor<'a, E: ExecutableDocument, S: SchemaDefinition> {
6    fn new(
7        executable_document: &'a E,
8        schema_definition: &'a S,
9        cache: &'a Cache<'a, E, S>,
10    ) -> Self;
11
12    fn visit_operation_definition(&mut self, _operation_definition: &'a E::OperationDefinition) {}
13
14    fn visit_selection_set(
15        &mut self,
16        _selection_set: &'a E::SelectionSet,
17        _type: TypeDefinitionReference<'a, S::TypeDefinition>,
18    ) {
19    }
20
21    fn visit_field(
22        &mut self,
23        _field: &'a E::Field,
24        _field_definition: &'a S::FieldDefinition,
25        _path: &Path<'a, E>,
26    ) {
27    }
28
29    fn visit_const_directive(
30        &mut self,
31        _directive: &'a E::Directive<true>,
32        _location: DirectiveLocation,
33    ) {
34    }
35
36    fn visit_variable_directive(
37        &mut self,
38        _directive: &'a E::Directive<false>,
39        _location: DirectiveLocation,
40    ) {
41    }
42
43    fn visit_const_directives(
44        &mut self,
45        _directives: &'a E::Directives<true>,
46        _location: DirectiveLocation,
47    ) {
48    }
49
50    fn visit_variable_directives(
51        &mut self,
52        _directives: &'a E::Directives<false>,
53        _location: DirectiveLocation,
54    ) {
55    }
56
57    fn visit_fragment_definition(&mut self, _fragment_definition: &'a E::FragmentDefinition) {}
58
59    fn visit_inline_fragment(
60        &mut self,
61        _inline_fragment: &'a E::InlineFragment,
62        _scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
63    ) {
64    }
65
66    fn visit_fragment_spread(
67        &mut self,
68        _fragment_spread: &'a E::FragmentSpread,
69        _scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
70        _path: &Path<'a, E>,
71    ) {
72    }
73
74    fn visit_const_argument(
75        &mut self,
76        _argument: &'a E::Argument<true>,
77        _input_value_definition: &'a S::InputValueDefinition,
78    ) {
79    }
80
81    fn visit_variable_argument(
82        &mut self,
83        _argument: &'a E::Argument<false>,
84        _input_value_definition: &'a S::InputValueDefinition,
85        _path: &Path<'a, E>,
86    ) {
87    }
88
89    fn visit_variable_definition(&mut self, _variable_definition: &'a E::VariableDefinition) {}
90
91    fn visit_variable_definitions(&mut self, _variable_definitions: &'a E::VariableDefinitions) {}
92}
93
94macro_rules! impl_visitor {
95    ($n:literal) => {
96        seq_macro::seq!(N in 0..$n {
97            #[warn(clippy::missing_trait_methods)]
98            impl<'a, E: ExecutableDocument, S: SchemaDefinition, #(T~N: Visitor<'a, E, S>,)*> Visitor<'a, E, S> for (#(T~N,)*) {
99                fn new(
100                    executable_document: &'a E,
101                    schema_definition: &'a S,
102                    cache: &'a Cache<'a, E, S>,
103                ) -> Self {
104                    (
105                        #(T~N::new(
106                            executable_document,
107                            schema_definition,
108                            cache,
109                        ),)*
110                    )
111                }
112
113                fn visit_operation_definition(&mut self, operation_definition: &'a E::OperationDefinition) {
114                    #(self.N.visit_operation_definition(operation_definition);)*
115                }
116
117                fn visit_selection_set(
118                    &mut self,
119                    selection_set: &'a E::SelectionSet,
120                    r#type: TypeDefinitionReference<'a, S::TypeDefinition>,
121                ) {
122                    #(self.N.visit_selection_set(selection_set, r#type);)*
123                }
124
125                fn visit_field(
126                    &mut self,
127                    field: &'a E::Field,
128                    field_definition: &'a S::FieldDefinition,
129                    path: &Path<'a, E>,
130                ) {
131                    #(self.N.visit_field(field, field_definition, path);)*
132                }
133
134                fn visit_const_directive(
135                    &mut self,
136                    directive: &'a E::Directive<true>,
137                    location: DirectiveLocation,
138                ) {
139                    #(self.N.visit_const_directive(directive, location);)*
140                }
141
142                fn visit_variable_directive(
143                    &mut self,
144                    directive: &'a E::Directive<false>,
145                    location: DirectiveLocation,
146                ) {
147                    #(self.N.visit_variable_directive(directive, location);)*
148                }
149
150                fn visit_const_directives(
151                    &mut self,
152                    directives: &'a E::Directives<true>,
153                    location: DirectiveLocation,
154                ) {
155                    #(self.N.visit_const_directives(directives, location);)*
156                }
157
158                fn visit_variable_directives(
159                    &mut self,
160                    directives: &'a E::Directives<false>,
161                    location: DirectiveLocation,
162                ) {
163                    #(self.N.visit_variable_directives(directives, location);)*
164                }
165
166                fn visit_fragment_definition(&mut self, fragment_definition: &'a E::FragmentDefinition) {
167                    #(self.N.visit_fragment_definition(fragment_definition);)*
168                }
169
170                fn visit_inline_fragment(
171                    &mut self,
172                    inline_fragment: &'a E::InlineFragment,
173                    scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
174                ) {
175                    #(self.N.visit_inline_fragment(inline_fragment, scoped_type);)*
176                }
177
178                fn visit_fragment_spread(
179                    &mut self,
180                    fragment_spread: &'a E::FragmentSpread,
181                    scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
182                    path: &Path<'a, E>,
183                ) {
184                    #(self.N.visit_fragment_spread(fragment_spread, scoped_type, path);)*
185                }
186
187                fn visit_const_argument(
188                    &mut self,
189                    argument: &'a E::Argument<true>,
190                    input_value_definition: &'a S::InputValueDefinition,
191                ) {
192                    #(self.N.visit_const_argument(argument, input_value_definition);)*
193                }
194
195                fn visit_variable_argument(
196                    &mut self,
197                    argument: &'a E::Argument<false>,
198                    input_value_definition: &'a S::InputValueDefinition,
199                    path: &Path<'a, E>,
200                ) {
201                    #(self.N.visit_variable_argument(argument, input_value_definition, path);)*
202                }
203
204                fn visit_variable_definition(&mut self, variable_definition: &'a E::VariableDefinition) {
205                    #(self.N.visit_variable_definition(variable_definition);)*
206                }
207
208                fn visit_variable_definitions(&mut self, variable_definitions: &'a E::VariableDefinitions) {
209                    #(self.N.visit_variable_definitions(variable_definitions);)*
210                }
211            }
212        });
213    }
214}
215
216seq_macro::seq!(N in 2..=10 {
217    impl_visitor!(N);
218});
219
220impl_visitor!(26);