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