diff --git a/compiler/crates/relay-typegen/src/lib.rs b/compiler/crates/relay-typegen/src/lib.rs index 3370cafcf9c8d..e2a30546b94e3 100644 --- a/compiler/crates/relay-typegen/src/lib.rs +++ b/compiler/crates/relay-typegen/src/lib.rs @@ -156,8 +156,10 @@ fn generate_fragment_type_exports_section_impl( .is_some(), fragment_definition.name.map(|x| x.0), fragment_locations, - false, - is_extra_artifact_branch_module, + TypegenOptions { + no_optional_fields_in_raw_response_type: false, + is_extra_artifact_branch_module, + }, ); let mut writer = new_writer_from_config(&project_config.typegen_config); write_fragment_type_exports_section(&typegen_context, fragment_definition, &mut writer) @@ -180,8 +182,10 @@ pub fn generate_named_validator_export( .is_some(), fragment_definition.name.map(|x| x.0), fragment_locations, - false, - false, + TypegenOptions { + no_optional_fields_in_raw_response_type: false, + is_extra_artifact_branch_module: false, + }, ); let mut writer = new_writer_from_config(&project_config.typegen_config); write_validator_function(&typegen_context, fragment_definition, &mut writer).unwrap(); @@ -217,8 +221,10 @@ pub fn generate_operation_type_exports_section( typegen_operation.name.item.0, ), fragment_locations, - false, - false, + TypegenOptions { + no_optional_fields_in_raw_response_type: false, + is_extra_artifact_branch_module: false, + }, ); let mut writer = new_writer_from_config(&project_config.typegen_config); write_operation_type_exports_section( @@ -252,8 +258,10 @@ pub fn generate_split_operation_type_exports_section( typegen_operation.name.item.0, ), fragment_locations, - no_optional_fields_in_raw_response_type, - false, + TypegenOptions { + no_optional_fields_in_raw_response_type, + is_extra_artifact_branch_module: false, + }, ); let mut writer = new_writer_from_config(&project_config.typegen_config); @@ -276,10 +284,7 @@ struct TypegenContext<'a> { has_unified_output: bool, generating_updatable_types: bool, definition_source_location: WithLocation, - // All keys in raw response should be required - no_optional_fields_in_raw_response_type: bool, - // Some extra artifacts require special type generation - is_extra_artifact_branch_module: bool, + typegen_options: TypegenOptions, } impl<'a> TypegenContext<'a> { @@ -289,8 +294,7 @@ impl<'a> TypegenContext<'a> { generating_updatable_types: bool, definition_source_location: WithLocation, fragment_locations: &'a FragmentLocations, - no_optional_fields_in_raw_response_type: bool, - is_extra_artifact_branch_module: bool, + typegen_options: TypegenOptions, ) -> Self { Self { schema, @@ -299,8 +303,14 @@ impl<'a> TypegenContext<'a> { has_unified_output: project_config.output.is_some(), generating_updatable_types, definition_source_location, - no_optional_fields_in_raw_response_type, - is_extra_artifact_branch_module, + typegen_options, } } } + +struct TypegenOptions { + // All keys in raw response should be required + no_optional_fields_in_raw_response_type: bool, + // Some extra artifacts require special type generation + is_extra_artifact_branch_module: bool, +} diff --git a/compiler/crates/relay-typegen/src/visit.rs b/compiler/crates/relay-typegen/src/visit.rs index c19e049fa0018..2049a63bcfb8a 100644 --- a/compiler/crates/relay-typegen/src/visit.rs +++ b/compiler/crates/relay-typegen/src/visit.rs @@ -1682,8 +1682,10 @@ fn raw_response_make_prop( runtime_imports: &mut RuntimeImports, custom_scalars: &mut CustomScalarsImports, ) -> Prop { - let optional = - !typegen_context.no_optional_fields_in_raw_response_type && type_selection.is_conditional(); + let optional = !typegen_context + .typegen_options + .no_optional_fields_in_raw_response_type + && type_selection.is_conditional(); match type_selection { TypeSelection::ModuleDirective(module_directive) => Prop::Spread(SpreadProp { value: module_directive.fragment_name.0, diff --git a/compiler/crates/relay-typegen/src/write.rs b/compiler/crates/relay-typegen/src/write.rs index cc6afff095485..81d41691ecfd2 100644 --- a/compiler/crates/relay-typegen/src/write.rs +++ b/compiler/crates/relay-typegen/src/write.rs @@ -453,7 +453,10 @@ pub(crate) fn write_fragment_type_exports_section( if !is_assignable_fragment { writer.write_export_type(&data_type_name, &data_type)?; writer.write_export_type(&format!("{}$key", fragment_definition.name.item), &ref_type)?; - } else if typegen_context.is_extra_artifact_branch_module { + } else if typegen_context + .typegen_options + .is_extra_artifact_branch_module + { writer.write_export_type(&data_type_name, &data_type)?; }