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
use crate::deprecation::DeprecationStrategy;
use crate::normalization::Normalization;
use proc_macro2::Ident;
use std::path::{Path, PathBuf};
use syn::{self, Visibility};
pub struct GraphQLClientCodegenOptions {
pub operation_name: Option<String>,
pub struct_name: Option<String>,
struct_ident: Option<Ident>,
variables_derives: Option<String>,
response_derives: Option<String>,
deprecation_strategy: Option<DeprecationStrategy>,
module_visibility: Option<Visibility>,
query_file: Option<PathBuf>,
schema_file: Option<PathBuf>,
normalization: Normalization,
custom_scalars_module: Option<syn::Path>,
extern_enums: Vec<String>,
}
impl GraphQLClientCodegenOptions {
pub fn new() -> GraphQLClientCodegenOptions {
GraphQLClientCodegenOptions {
variables_derives: Default::default(),
response_derives: Default::default(),
deprecation_strategy: Default::default(),
module_visibility: Default::default(),
operation_name: Default::default(),
struct_ident: Default::default(),
struct_name: Default::default(),
query_file: Default::default(),
schema_file: Default::default(),
normalization: Normalization::Rust,
custom_scalars_module: Default::default(),
extern_enums: Default::default(),
}
}
pub(crate) fn module_visibility(&self) -> &Visibility {
self.module_visibility
.as_ref()
.unwrap_or(&Visibility::Inherited)
}
pub(crate) fn deprecation_strategy(&self) -> DeprecationStrategy {
self.deprecation_strategy.clone().unwrap_or_default()
}
pub fn set_query_file(&mut self, path: PathBuf) {
self.query_file = Some(path);
}
pub fn variables_derives(&self) -> Option<&str> {
self.variables_derives.as_deref()
}
pub fn set_variables_derives(&mut self, variables_derives: String) {
self.variables_derives = Some(variables_derives);
}
pub fn all_variable_derives(&self) -> impl Iterator<Item = &str> {
let additional = self
.variables_derives
.as_deref()
.into_iter()
.flat_map(|s| s.split(','));
vec!["Serialize", "Deserialize", "Debug", "Clone"].into_iter().chain(additional)
}
pub fn all_response_derives(&self) -> impl Iterator<Item = &str> {
let base_derives = vec!["Serialize", "Deserialize", "Debug", "Clone"].into_iter();
base_derives.chain(
self.additional_response_derives(),
)
}
pub fn additional_response_derives(&self) -> impl Iterator<Item = &str> {
self.response_derives
.as_deref()
.into_iter()
.flat_map(|s| s.split(','))
.map(|s| s.trim())
}
pub fn set_response_derives(&mut self, response_derives: String) {
self.response_derives = Some(response_derives);
}
pub fn set_deprecation_strategy(&mut self, deprecation_strategy: DeprecationStrategy) {
self.deprecation_strategy = Some(deprecation_strategy);
}
pub fn set_module_visibility(&mut self, visibility: Visibility) {
self.module_visibility = Some(visibility);
}
pub fn set_struct_name(&mut self, struct_name: String) {
self.struct_name = Some(struct_name);
}
pub fn set_operation_name(&mut self, operation_name: String) {
self.operation_name = Some(operation_name);
}
pub fn schema_file(&self) -> Option<&Path> {
self.schema_file.as_deref()
}
pub fn query_file(&self) -> Option<&Path> {
self.query_file.as_deref()
}
pub fn set_struct_ident(&mut self, ident: Ident) {
self.struct_ident = Some(ident);
}
pub fn struct_ident(&self) -> Option<&proc_macro2::Ident> {
self.struct_ident.as_ref()
}
pub fn set_normalization(&mut self, norm: Normalization) {
self.normalization = norm;
}
pub fn normalization(&self) -> &Normalization {
&self.normalization
}
pub fn custom_scalars_module(&self) -> Option<&syn::Path> {
self.custom_scalars_module.as_ref()
}
pub fn set_custom_scalars_module(&mut self, module: syn::Path) {
self.custom_scalars_module = Some(module)
}
pub fn extern_enums(&self) -> &[String] {
&self.extern_enums
}
pub fn set_extern_enums(&mut self, enums: Vec<String>) {
self.extern_enums = enums;
}
}