@@ -8,6 +8,7 @@ use crate::resolution::SelectionRef;
8
8
use crate :: schema:: TypeRef ;
9
9
use crate :: shared:: field_rename_annotation;
10
10
use crate :: {
11
+ deprecation:: DeprecationStrategy ,
11
12
field_type:: GraphqlTypeQualifier ,
12
13
// deprecation::DeprecationStrategy,
13
14
resolution:: { InlineFragment , OperationRef , ResolvedQuery , Selection , SelectionId } ,
@@ -198,6 +199,7 @@ fn calculate_selection<'a>(
198
199
graphql_name : None ,
199
200
rust_name : fragment_ref. name ( ) . to_snake_case ( ) . into ( ) ,
200
201
struct_id,
202
+ deprecation : None ,
201
203
} )
202
204
}
203
205
}
@@ -231,6 +233,7 @@ fn calculate_selection<'a>(
231
233
field_type : context. schema ( ) . r#enum ( enm) . name ( ) . into ( ) ,
232
234
field_type_qualifiers : schema_field. type_qualifiers ( ) ,
233
235
flatten : false ,
236
+ deprecation : schema_field. deprecation ( ) ,
234
237
} ) ;
235
238
}
236
239
TypeId :: Scalar ( scalar) => {
@@ -243,6 +246,7 @@ fn calculate_selection<'a>(
243
246
struct_id,
244
247
rust_name,
245
248
flatten : false ,
249
+ deprecation : schema_field. deprecation ( ) ,
246
250
} ) ;
247
251
}
248
252
TypeId :: Object ( _) | TypeId :: Interface ( _) | TypeId :: Union ( _) => {
@@ -255,6 +259,7 @@ fn calculate_selection<'a>(
255
259
field_type_qualifiers : schema_field. type_qualifiers ( ) ,
256
260
field_type : Cow :: Owned ( struct_name_string. clone ( ) ) ,
257
261
flatten : false ,
262
+ deprecation : schema_field. deprecation ( ) ,
258
263
} ) ;
259
264
260
265
let type_id = context. push_type ( ExpandedType {
@@ -298,6 +303,7 @@ fn calculate_selection<'a>(
298
303
rust_name : final_field_name,
299
304
struct_id,
300
305
flatten : true ,
306
+ deprecation : None ,
301
307
} ) ;
302
308
303
309
// We stop here, because the structs for the fragments are generated separately, to
@@ -317,10 +323,11 @@ struct ExpandedField<'a> {
317
323
field_type_qualifiers : & ' a [ GraphqlTypeQualifier ] ,
318
324
struct_id : ResponseTypeId ,
319
325
flatten : bool ,
326
+ deprecation : Option < Option < & ' a str > > ,
320
327
}
321
328
322
329
impl < ' a > ExpandedField < ' a > {
323
- fn render ( & self ) -> TokenStream {
330
+ fn render ( & self , options : & GraphQLClientCodegenOptions ) -> Option < TokenStream > {
324
331
let ident = Ident :: new ( & self . rust_name , Span :: call_site ( ) ) ;
325
332
let qualified_type = decorate_type (
326
333
& Ident :: new ( & self . field_type , Span :: call_site ( ) ) ,
@@ -337,28 +344,25 @@ impl<'a> ExpandedField<'a> {
337
344
None
338
345
} ;
339
346
340
- // TODO: deprecation
341
- // let deprecation_annotation = match (
342
- // field.schema_field().is_deprecated(),
343
- // options.deprecation_strategy(),
344
- // ) {
345
- // (false, _) | (true, DeprecationStrategy::Allow) => None,
346
- // (true, DeprecationStrategy::Warn) => {
347
- // let msg = field
348
- // .schema_field()
349
- // .deprecation_message()
350
- // .unwrap_or("This field is deprecated.");
351
-
352
- // Some(quote!(#[deprecated(note = #msg)]))
353
- // }
354
- // (true, DeprecationStrategy::Deny) => continue,
355
- // };
356
-
357
- quote ! {
347
+ let optional_deprecation_annotation =
348
+ match ( self . deprecation , options. deprecation_strategy ( ) ) {
349
+ ( None , _) | ( Some ( _) , DeprecationStrategy :: Allow ) => None ,
350
+ ( Some ( msg) , DeprecationStrategy :: Warn ) => {
351
+ let optional_msg = msg. map ( |msg| quote ! ( ( note = #msg) ) ) ;
352
+
353
+ Some ( quote ! ( #[ deprecated#optional_msg] ) )
354
+ }
355
+ ( Some ( _) , DeprecationStrategy :: Deny ) => return None ,
356
+ } ;
357
+
358
+ let tokens = quote ! {
358
359
#optional_flatten
359
360
#optional_rename
361
+ #optional_deprecation_annotation
360
362
pub #ident: #qualified_type
361
- }
363
+ } ;
364
+
365
+ Some ( tokens)
362
366
}
363
367
}
364
368
@@ -449,7 +453,7 @@ impl<'a> ExpandedSelection<'a> {
449
453
. fields
450
454
. iter ( )
451
455
. filter ( |field| field. struct_id == type_id)
452
- . map ( |field| field. render ( ) )
456
+ . filter_map ( |field| field. render ( self . options ) )
453
457
. peekable ( ) ;
454
458
455
459
let on_variants: Vec < TokenStream > = self
0 commit comments