File tree Expand file tree Collapse file tree 3 files changed +27
-4
lines changed
graphql_client_codegen/src Expand file tree Collapse file tree 3 files changed +27
-4
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ fn skip_serializing_none() {
13
13
use skip_serializing_none_mutation:: * ;
14
14
15
15
let query = SkipSerializingNoneMutation :: build_query ( Variables {
16
+ foo : None ,
16
17
param : Some ( Param {
17
18
data : Author {
18
19
name : "test" . to_owned ( ) ,
@@ -25,5 +26,18 @@ fn skip_serializing_none() {
25
26
26
27
println ! ( "{}" , stringified) ;
27
28
28
- assert ! ( stringified. contains( r#""data":{"name":"test"}"# ) ) ;
29
+ assert ! ( stringified. contains( r#""variables":{"param":{"data":{"name":"test"}}}"# ) ) ;
30
+
31
+ let query = SkipSerializingNoneMutation :: build_query ( Variables {
32
+ foo : Some ( 42 ) ,
33
+ param : Some ( Param {
34
+ data : Author {
35
+ name : "test" . to_owned ( ) ,
36
+ id : None ,
37
+ } ,
38
+ } ) ,
39
+ } ) ;
40
+ let stringified = serde_json:: to_string ( & query) . expect ( "SkipSerializingNoneMutation is valid" ) ;
41
+ println ! ( "{}" , stringified) ;
42
+ assert ! ( stringified. contains( r#""variables":{"param":{"data":{"name":"test"}},"foo":42}"# ) ) ;
29
43
}
Original file line number Diff line number Diff line change 1
- mutation SkipSerializingNoneMutation ($param : Param ) {
1
+ mutation SkipSerializingNoneMutation ($param : Param , $foo : Int ) {
2
2
optInput (query : $param ) {
3
3
name
4
4
__typename
Original file line number Diff line number Diff line change @@ -135,10 +135,19 @@ fn generate_variable_struct_field(
135
135
let snake_case_name = variable. name . to_snake_case ( ) ;
136
136
let safe_name = shared:: keyword_replace ( & snake_case_name) ;
137
137
let ident = Ident :: new ( & safe_name, Span :: call_site ( ) ) ;
138
- let annotation = shared:: field_rename_annotation ( & variable. name , & safe_name) ;
138
+ let rename_annotation = shared:: field_rename_annotation ( & variable. name , & safe_name) ;
139
+ let skip_serializing_annotation = if * options. skip_serializing_none ( ) {
140
+ if variable. r#type . qualifiers . first ( ) != Some ( & GraphqlTypeQualifier :: Required ) {
141
+ Some ( quote ! ( #[ serde( skip_serializing_if = "Option::is_none" ) ] ) )
142
+ } else {
143
+ None
144
+ }
145
+ } else {
146
+ None
147
+ } ;
139
148
let r#type = render_variable_field_type ( variable, options, query) ;
140
149
141
- quote:: quote!( #annotation pub #ident : #r#type)
150
+ quote:: quote!( #skip_serializing_annotation #rename_annotation pub #ident : #r#type)
142
151
}
143
152
144
153
fn generate_scalar_definitions < ' a , ' schema : ' a > (
You can’t perform that action at this time.
0 commit comments