Skip to content

Commit bc5e9f1

Browse files
committed
Finished implementing skip_serializing_none feature
1 parent 39772fd commit bc5e9f1

File tree

6 files changed

+27
-27
lines changed

6 files changed

+27
-27
lines changed

graphql_client_codegen/src/codegen/inputs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ pub(super) fn generate_input_object_definitions(
2929
let normalized_field_type_name = options
3030
.normalization()
3131
.field_type(field_type.id.name(query.schema));
32-
let optional_skip_none = if *options.skip_none() && field_type.is_optional() {
32+
let optional_skip_serializing_none = if *options.skip_serializing_none() && field_type.is_optional() {
3333
Some(quote!(#[serde(skip_serializing_if = "Option::is_none")]))
3434
} else {
3535
None
@@ -48,7 +48,7 @@ pub(super) fn generate_input_object_definitions(
4848
};
4949

5050
quote!(
51-
#optional_skip_none
51+
#optional_skip_serializing_none
5252
#annotation pub #name_ident: #field_type
5353
)
5454
});

graphql_client_codegen/src/codegen/selection.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ impl<'a> ExpandedField<'a> {
405405
qualified_type
406406
};
407407

408-
let optional_skip_none = if *options.skip_none()
408+
let optional_skip_serializing_none = if *options.skip_serializing_none()
409409
&& self
410410
.field_type_qualifiers
411411
.get(0)
@@ -439,7 +439,7 @@ impl<'a> ExpandedField<'a> {
439439
};
440440

441441
let tokens = quote! {
442-
#optional_skip_none
442+
#optional_skip_serializing_none
443443
#optional_flatten
444444
#optional_rename
445445
#optional_deprecation_annotation

graphql_client_codegen/src/codegen_options.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub struct GraphQLClientCodegenOptions {
4646
/// Flag to trigger generation of Other variant for fragments Enum
4747
fragments_other_variant: bool,
4848
/// Skip Serialization of None values.
49-
skip_none: bool,
49+
skip_serializing_none: bool,
5050
}
5151

5252
impl GraphQLClientCodegenOptions {
@@ -67,7 +67,7 @@ impl GraphQLClientCodegenOptions {
6767
custom_scalars_module: Default::default(),
6868
extern_enums: Default::default(),
6969
fragments_other_variant: Default::default(),
70-
skip_none: Default::default(),
70+
skip_serializing_none: Default::default(),
7171
}
7272
}
7373

@@ -219,12 +219,12 @@ impl GraphQLClientCodegenOptions {
219219
}
220220

221221
/// Set the graphql client codegen option's skip none value.
222-
pub fn set_skip_none(&mut self, skip_none: bool) {
223-
self.skip_none = skip_none
222+
pub fn set_skip_serializing_none(&mut self, skip_serializing_none: bool) {
223+
self.skip_serializing_none = skip_serializing_none
224224
}
225225

226226
/// Get a reference to the graphql client codegen option's skip none value.
227-
pub fn skip_none(&self) -> &bool {
228-
&self.skip_none
227+
pub fn skip_serializing_none(&self) -> &bool {
228+
&self.skip_serializing_none
229229
}
230230
}

graphql_client_codegen/src/tests/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ fn fragments_other_variant_false_should_not_generate_unknown_other_variant() {
119119
}
120120

121121
#[test]
122-
fn skip_none_should_generate_serde_skip_serializing() {
122+
fn skip_serializing_none_should_generate_serde_skip_serializing() {
123123
let query_string = include_str!("keywords_query.graphql");
124124
let query = graphql_parser::parse_query::<&str>(query_string).expect("Parse keywords query");
125125
let schema = graphql_parser::parse_schema(include_str!("keywords_schema.graphql"))
@@ -129,7 +129,7 @@ fn skip_none_should_generate_serde_skip_serializing() {
129129

130130
let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Cli);
131131

132-
options.set_skip_none(true);
132+
options.set_skip_serializing_none(true);
133133

134134
let query = crate::query::resolve(&schema, &query).unwrap();
135135

graphql_query_derive/src/attributes.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ pub fn extract_fragments_other_variant(ast: &syn::DeriveInput) -> bool {
103103
.unwrap_or(false)
104104
}
105105

106-
pub fn extract_skip_none(ast: &syn::DeriveInput) -> bool {
107-
extract_attr(ast, "skip_none")
106+
pub fn extract_skip_serializing_none(ast: &syn::DeriveInput) -> bool {
107+
extract_attr(ast, "skip_serializing_none")
108108
.ok()
109109
.and_then(|s| FromStr::from_str(s.as_str()).ok())
110110
.unwrap_or(false)
@@ -228,52 +228,52 @@ mod test {
228228
}
229229

230230
#[test]
231-
fn test_skip_none_set_to_true() {
231+
fn test_skip_serializing_none_set_to_true() {
232232
let input = r#"
233233
#[derive(GraphQLQuery)]
234234
#[graphql(
235235
schema_path = "x",
236236
query_path = "x",
237-
skip_none = "true"
237+
skip_serializing_none = "true"
238238
)]
239239
struct MyQuery;
240240
"#;
241241
let parsed = syn::parse_str(input).unwrap();
242-
assert!(extract_skip_none(&parsed));
242+
assert!(extract_skip_serializing_none(&parsed));
243243
}
244244

245245
#[test]
246-
fn test_skip_none_set_to_false() {
246+
fn test_skip_serializing_none_set_to_false() {
247247
let input = r#"
248248
#[derive(GraphQLQuery)]
249249
#[graphql(
250250
schema_path = "x",
251251
query_path = "x",
252-
skip_none = "false"
252+
skip_serializing_none = "false"
253253
)]
254254
struct MyQuery;
255255
"#;
256256
let parsed = syn::parse_str(input).unwrap();
257-
assert!(!extract_skip_none(&parsed));
257+
assert!(!extract_skip_serializing_none(&parsed));
258258
}
259259

260260
#[test]
261-
fn test_skip_none_set_to_invalid() {
261+
fn test_skip_serializing_none_set_to_invalid() {
262262
let input = r#"
263263
#[derive(GraphQLQuery)]
264264
#[graphql(
265265
schema_path = "x",
266266
query_path = "x",
267-
skip_none = "invalid"
267+
skip_serializing_none = "invalid"
268268
)]
269269
struct MyQuery;
270270
"#;
271271
let parsed = syn::parse_str(input).unwrap();
272-
assert!(!extract_skip_none(&parsed));
272+
assert!(!extract_skip_serializing_none(&parsed));
273273
}
274274

275275
#[test]
276-
fn test_skip_none_unset() {
276+
fn test_skip_serializing_none_unset() {
277277
let input = r#"
278278
#[derive(GraphQLQuery)]
279279
#[graphql(
@@ -283,6 +283,6 @@ mod test {
283283
struct MyQuery;
284284
"#;
285285
let parsed = syn::parse_str(input).unwrap();
286-
assert!(!extract_skip_none(&parsed));
286+
assert!(!extract_skip_serializing_none(&parsed));
287287
}
288288
}

graphql_query_derive/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@ fn build_graphql_client_derive_options(
6464
let custom_scalars_module = attributes::extract_attr(input, "custom_scalars_module").ok();
6565
let extern_enums = attributes::extract_attr_list(input, "extern_enums").ok();
6666
let fragments_other_variant: bool = attributes::extract_fragments_other_variant(input);
67-
let skip_none: bool = attributes::extract_skip_none(input);
67+
let skip_serializing_none: bool = attributes::extract_skip_serializing_none(input);
6868

6969
let mut options = GraphQLClientCodegenOptions::new(CodegenMode::Derive);
7070
options.set_query_file(query_path);
7171
options.set_fragments_other_variant(fragments_other_variant);
72-
options.set_skip_none(skip_none);
72+
options.set_skip_serializing_none(skip_serializing_none);
7373

7474
if let Some(variables_derives) = variables_derives {
7575
options.set_variables_derives(variables_derives);

0 commit comments

Comments
 (0)