@@ -320,12 +320,16 @@ pub fn shopify_function_target(
320
320
. schema_path
321
321
. expect ( "No value given for schema_path" )
322
322
. value ( ) ;
323
- let extern_enums = args. extern_enums . as_ref ( ) . map ( extract_extern_enums) ;
323
+ let extern_enums = args
324
+ . extern_enums
325
+ . as_ref ( )
326
+ . map ( extract_extern_enums)
327
+ . unwrap_or_else ( default_exter_enums) ;
324
328
325
329
let input_struct = generate_input_struct (
326
330
query_path. as_str ( ) ,
327
331
schema_path. as_str ( ) ,
328
- extern_enums. as_deref ( ) ,
332
+ extern_enums. as_slice ( ) ,
329
333
) ;
330
334
331
335
if let Err ( error) = extract_shopify_function_return_type ( & ast) {
@@ -341,7 +345,7 @@ pub fn shopify_function_target(
341
345
& target_handle_string. to_case( Case :: Camel )
342
346
) ;
343
347
let output_struct =
344
- generate_output_struct ( & output_query, schema_path. as_str ( ) , extern_enums. as_deref ( ) ) ;
348
+ generate_output_struct ( & output_query, schema_path. as_str ( ) , extern_enums. as_slice ( ) ) ;
345
349
346
350
if let Err ( error) = extract_shopify_function_return_type ( & ast) {
347
351
return error. to_compile_error ( ) . into ( ) ;
@@ -411,15 +415,20 @@ pub fn generate_types(attr: proc_macro::TokenStream) -> proc_macro::TokenStream
411
415
. schema_path
412
416
. expect ( "No value given for schema_path" )
413
417
. value ( ) ;
414
- let extern_enums = args. extern_enums . as_ref ( ) . map ( extract_extern_enums) ;
418
+ let extern_enums = args
419
+ . extern_enums
420
+ . as_ref ( )
421
+ . map ( extract_extern_enums)
422
+ . unwrap_or_else ( default_exter_enums) ;
423
+
415
424
let input_struct = generate_input_struct (
416
425
query_path. as_str ( ) ,
417
426
schema_path. as_str ( ) ,
418
- extern_enums. as_deref ( ) ,
427
+ extern_enums. as_slice ( ) ,
419
428
) ;
420
429
let output_query =
421
430
"mutation Output($result: FunctionResult!) {\n handleResult(result: $result)\n }\n " ;
422
- let output_struct = generate_output_struct ( output_query, & schema_path, extern_enums. as_deref ( ) ) ;
431
+ let output_struct = generate_output_struct ( output_query, & schema_path, extern_enums. as_slice ( ) ) ;
423
432
424
433
quote ! {
425
434
#input_struct
@@ -433,12 +442,8 @@ const DEFAULT_EXTERN_ENUMS: &[&str] = &["LanguageCode", "CountryCode", "Currency
433
442
fn generate_input_struct (
434
443
query_path : & str ,
435
444
schema_path : & str ,
436
- extern_enums : Option < & [ String ] > ,
445
+ extern_enums : & [ String ] ,
437
446
) -> TokenStream {
438
- let extern_enums = extern_enums
439
- . map ( |e| e. to_owned ( ) )
440
- . unwrap_or_else ( || DEFAULT_EXTERN_ENUMS . iter ( ) . map ( |e| e. to_string ( ) ) . collect ( ) ) ;
441
-
442
447
quote ! {
443
448
#[ derive( graphql_client:: GraphQLQuery , Clone , Debug , serde:: Deserialize , PartialEq ) ]
444
449
#[ graphql(
@@ -455,7 +460,7 @@ fn generate_input_struct(
455
460
456
461
fn graphql_codegen_options (
457
462
operation_name : String ,
458
- extern_enums : Option < & [ String ] > ,
463
+ extern_enums : & [ String ] ,
459
464
) -> GraphQLClientCodegenOptions {
460
465
let mut options = GraphQLClientCodegenOptions :: new ( CodegenMode :: Derive ) ;
461
466
options. set_operation_name ( operation_name) ;
@@ -468,17 +473,15 @@ fn graphql_codegen_options(
468
473
}
469
474
. into ( ) ,
470
475
) ;
471
- if let Some ( extern_enums) = extern_enums {
472
- options. set_extern_enums ( extern_enums. to_vec ( ) ) ;
473
- }
476
+ options. set_extern_enums ( extern_enums. to_vec ( ) ) ;
474
477
475
478
options
476
479
}
477
480
478
481
fn generate_output_struct (
479
482
query : & str ,
480
483
schema_path : & str ,
481
- extern_enums : Option < & [ String ] > ,
484
+ extern_enums : & [ String ] ,
482
485
) -> proc_macro2:: TokenStream {
483
486
let options = graphql_codegen_options ( "Output" . to_string ( ) , extern_enums) ;
484
487
let cargo_manifest_dir =
@@ -511,6 +514,10 @@ fn extract_extern_enums(extern_enums: &ExprArray) -> Vec<String> {
511
514
. collect ( )
512
515
}
513
516
517
+ fn default_exter_enums ( ) -> Vec < String > {
518
+ DEFAULT_EXTERN_ENUMS . iter ( ) . map ( |e| e. to_string ( ) ) . collect ( )
519
+ }
520
+
514
521
#[ cfg( test) ]
515
522
mod tests { }
516
523
0 commit comments