@@ -529,7 +529,27 @@ impl CodeGenerator for ShopifyFunctionCodeGenerator {
529529 }
530530 } ;
531531
532- vec ! [ serialize_impl]
532+ let field_values: Vec < syn:: FieldValue > = input_object_type_definition
533+ . input_field_definitions ( )
534+ . iter ( )
535+ . map ( |ivd| {
536+ let field_name_ident = names:: field_ident ( ivd. name ( ) ) ;
537+ let field_name_lit_str = syn:: LitStr :: new ( ivd. name ( ) , Span :: mixed_site ( ) ) ;
538+ parse_quote ! { #field_name_ident: shopify_function:: wasm_api:: Deserialize :: deserialize( & value. get_obj_prop( #field_name_lit_str) ) ? }
539+ } )
540+ . collect ( ) ;
541+
542+ let deserialize_impl = parse_quote ! {
543+ impl shopify_function:: wasm_api:: Deserialize for #name_ident {
544+ fn deserialize( value: & shopify_function:: wasm_api:: Value ) -> :: std:: result:: Result <Self , shopify_function:: wasm_api:: read:: Error > {
545+ Ok ( Self {
546+ #( #field_values) , *
547+ } )
548+ }
549+ }
550+ } ;
551+
552+ vec ! [ serialize_impl, deserialize_impl]
533553 }
534554
535555 fn additional_impls_for_one_of_input_object (
@@ -567,7 +587,47 @@ impl CodeGenerator for ShopifyFunctionCodeGenerator {
567587 }
568588 } ;
569589
570- vec ! [ serialize_impl]
590+ let deserialize_match_arms: Vec < syn:: Arm > = input_object_type_definition
591+ . input_field_definitions ( )
592+ . iter ( )
593+ . map ( |ivd| {
594+ let field_name_lit_str = syn:: LitStr :: new ( ivd. name ( ) , Span :: mixed_site ( ) ) ;
595+ let variant_ident = names:: enum_variant_ident ( ivd. name ( ) ) ;
596+
597+ parse_quote ! {
598+ #field_name_lit_str => {
599+ let value = shopify_function:: wasm_api:: Deserialize :: deserialize( & field_value) ?;
600+ Ok ( Self :: #variant_ident( value) )
601+ }
602+ }
603+ } )
604+ . collect ( ) ;
605+
606+ let deserialize_impl = parse_quote ! {
607+ impl shopify_function:: wasm_api:: Deserialize for #name_ident {
608+ fn deserialize( value: & shopify_function:: wasm_api:: Value ) -> :: std:: result:: Result <Self , shopify_function:: wasm_api:: read:: Error > {
609+ let Some ( obj_len) = value. obj_len( ) else {
610+ return Err ( shopify_function:: wasm_api:: read:: Error :: InvalidType ) ;
611+ } ;
612+
613+ if obj_len != 1 {
614+ return Err ( shopify_function:: wasm_api:: read:: Error :: InvalidType ) ;
615+ }
616+
617+ let Some ( field_name) = value. get_obj_key_at_index( 0 ) else {
618+ return Err ( shopify_function:: wasm_api:: read:: Error :: InvalidType ) ;
619+ } ;
620+ let field_value = value. get_at_index( 0 ) ;
621+
622+ match field_name. as_str( ) {
623+ #( #deserialize_match_arms) *
624+ _ => Err ( shopify_function:: wasm_api:: read:: Error :: InvalidType ) ,
625+ }
626+ }
627+ }
628+ } ;
629+
630+ vec ! [ serialize_impl, deserialize_impl]
571631 }
572632
573633 fn attributes_for_enum (
0 commit comments