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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
use crate::executable::{document::Path, Cache};
use bluejay_core::definition::{DirectiveLocation, SchemaDefinition, TypeDefinitionReference};
use bluejay_core::executable::ExecutableDocument;

pub trait Visitor<'a, E: ExecutableDocument, S: SchemaDefinition> {
    fn new(
        executable_document: &'a E,
        schema_definition: &'a S,
        cache: &'a Cache<'a, E, S>,
    ) -> Self;

    fn visit_operation_definition(&mut self, _operation_definition: &'a E::OperationDefinition) {}

    fn visit_selection_set(
        &mut self,
        _selection_set: &'a E::SelectionSet,
        _type: TypeDefinitionReference<'a, S::TypeDefinition>,
    ) {
    }

    fn visit_field(
        &mut self,
        _field: &'a E::Field,
        _field_definition: &'a S::FieldDefinition,
        _path: &Path<'a, E>,
    ) {
    }

    fn visit_const_directive(
        &mut self,
        _directive: &'a E::Directive<true>,
        _location: DirectiveLocation,
    ) {
    }

    fn visit_variable_directive(
        &mut self,
        _directive: &'a E::Directive<false>,
        _location: DirectiveLocation,
    ) {
    }

    fn visit_const_directives(
        &mut self,
        _directives: &'a E::Directives<true>,
        _location: DirectiveLocation,
    ) {
    }

    fn visit_variable_directives(
        &mut self,
        _directives: &'a E::Directives<false>,
        _location: DirectiveLocation,
    ) {
    }

    fn visit_fragment_definition(&mut self, _fragment_definition: &'a E::FragmentDefinition) {}

    fn visit_inline_fragment(
        &mut self,
        _inline_fragment: &'a E::InlineFragment,
        _scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
    ) {
    }

    fn visit_fragment_spread(
        &mut self,
        _fragment_spread: &'a E::FragmentSpread,
        _scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
        _path: &Path<'a, E>,
    ) {
    }

    fn visit_const_argument(
        &mut self,
        _argument: &'a E::Argument<true>,
        _input_value_definition: &'a S::InputValueDefinition,
    ) {
    }

    fn visit_variable_argument(
        &mut self,
        _argument: &'a E::Argument<false>,
        _input_value_definition: &'a S::InputValueDefinition,
        _path: &Path<'a, E>,
    ) {
    }

    fn visit_variable_definition(&mut self, _variable_definition: &'a E::VariableDefinition) {}

    fn visit_variable_definitions(&mut self, _variable_definitions: &'a E::VariableDefinitions) {}
}

macro_rules! impl_visitor {
    ($n:literal) => {
        seq_macro::seq!(N in 0..$n {
            #[warn(clippy::missing_trait_methods)]
            impl<'a, E: ExecutableDocument, S: SchemaDefinition, #(T~N: Visitor<'a, E, S>,)*> Visitor<'a, E, S> for (#(T~N,)*) {
                fn new(
                    executable_document: &'a E,
                    schema_definition: &'a S,
                    cache: &'a Cache<'a, E, S>,
                ) -> Self {
                    (
                        #(T~N::new(
                            executable_document,
                            schema_definition,
                            cache,
                        ),)*
                    )
                }

                fn visit_operation_definition(&mut self, operation_definition: &'a E::OperationDefinition) {
                    #(self.N.visit_operation_definition(operation_definition);)*
                }

                fn visit_selection_set(
                    &mut self,
                    selection_set: &'a E::SelectionSet,
                    r#type: TypeDefinitionReference<'a, S::TypeDefinition>,
                ) {
                    #(self.N.visit_selection_set(selection_set, r#type);)*
                }

                fn visit_field(
                    &mut self,
                    field: &'a E::Field,
                    field_definition: &'a S::FieldDefinition,
                    path: &Path<'a, E>,
                ) {
                    #(self.N.visit_field(field, field_definition, path);)*
                }

                fn visit_const_directive(
                    &mut self,
                    directive: &'a E::Directive<true>,
                    location: DirectiveLocation,
                ) {
                    #(self.N.visit_const_directive(directive, location);)*
                }

                fn visit_variable_directive(
                    &mut self,
                    directive: &'a E::Directive<false>,
                    location: DirectiveLocation,
                ) {
                    #(self.N.visit_variable_directive(directive, location);)*
                }

                fn visit_const_directives(
                    &mut self,
                    directives: &'a E::Directives<true>,
                    location: DirectiveLocation,
                ) {
                    #(self.N.visit_const_directives(directives, location);)*
                }

                fn visit_variable_directives(
                    &mut self,
                    directives: &'a E::Directives<false>,
                    location: DirectiveLocation,
                ) {
                    #(self.N.visit_variable_directives(directives, location);)*
                }

                fn visit_fragment_definition(&mut self, fragment_definition: &'a E::FragmentDefinition) {
                    #(self.N.visit_fragment_definition(fragment_definition);)*
                }

                fn visit_inline_fragment(
                    &mut self,
                    inline_fragment: &'a E::InlineFragment,
                    scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
                ) {
                    #(self.N.visit_inline_fragment(inline_fragment, scoped_type);)*
                }

                fn visit_fragment_spread(
                    &mut self,
                    fragment_spread: &'a E::FragmentSpread,
                    scoped_type: TypeDefinitionReference<'a, S::TypeDefinition>,
                    path: &Path<'a, E>,
                ) {
                    #(self.N.visit_fragment_spread(fragment_spread, scoped_type, path);)*
                }

                fn visit_const_argument(
                    &mut self,
                    argument: &'a E::Argument<true>,
                    input_value_definition: &'a S::InputValueDefinition,
                ) {
                    #(self.N.visit_const_argument(argument, input_value_definition);)*
                }

                fn visit_variable_argument(
                    &mut self,
                    argument: &'a E::Argument<false>,
                    input_value_definition: &'a S::InputValueDefinition,
                    path: &Path<'a, E>,
                ) {
                    #(self.N.visit_variable_argument(argument, input_value_definition, path);)*
                }

                fn visit_variable_definition(&mut self, variable_definition: &'a E::VariableDefinition) {
                    #(self.N.visit_variable_definition(variable_definition);)*
                }

                fn visit_variable_definitions(&mut self, variable_definitions: &'a E::VariableDefinitions) {
                    #(self.N.visit_variable_definitions(variable_definitions);)*
                }
            }
        });
    }
}

seq_macro::seq!(N in 2..=10 {
    impl_visitor!(N);
});

impl_visitor!(26);