Skip to content

Commit

Permalink
Export node from assignable fragment (#4409)
Browse files Browse the repository at this point in the history
Summary: Pull Request resolved: #4409

Reviewed By: alunyov

Differential Revision: D48286130

Pulled By: captbaritone

fbshipit-source-id: 99875a387e31d39403fcb3b9b68478561cf8977a
  • Loading branch information
tobias-tengler authored and facebook-github-bot committed Aug 21, 2023
1 parent 2400831 commit 1328fc1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
35 changes: 34 additions & 1 deletion compiler/crates/relay-compiler/src/artifact_content/content.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,6 +519,7 @@ pub fn generate_fragment(
project_config,
schema,
typegen_fragment,
source_hash,
skip_types,
fragment_locations,
)
Expand Down Expand Up @@ -668,6 +669,7 @@ fn generate_assignable_fragment(
project_config: &ProjectConfig,
schema: &SDLSchema,
typegen_fragment: &FragmentDefinition,
source_hash: Option<&String>,
skip_types: bool,
fragment_locations: &FragmentLocations,
) -> Result<Vec<u8>, FmtError> {
Expand Down Expand Up @@ -718,12 +720,43 @@ fn generate_assignable_fragment(
content_sections.push(ContentSection::Generic(section));
// -- End Types Section --

// -- Begin Fragment Node Section --
let mut section = GenericSection::default();
write_variable_value_with_type(
&project_config.typegen_config.language,
&mut section,
"node",
"any",
"{}",
)?;
content_sections.push(ContentSection::Generic(section));
// -- End Fragment Node Section --

// -- Begin Fragment Node Hash Section --
if let Some(source_hash) = source_hash {
let mut section = GenericSection::default();
write_source_hash(
config,
&project_config.typegen_config.language,
&mut section,
source_hash,
)?;
content_sections.push(ContentSection::Generic(section));
}
// -- End Fragment Node Hash Section --

// -- Begin Fragment Node Export Section --
let mut section = GenericSection::default();
write_export_generated_node(&project_config.typegen_config, &mut section, "node", None)?;
content_sections.push(ContentSection::Generic(section));
// -- End Fragment Node Export Section --

// -- Begin Export Section --
let mut section = GenericSection::default();
// Assignable fragments should never be passed to useFragment, and thus, we
// don't need to emit a reader fragment.
// Instead, we only need a named validator export, i.e.
// module.exports.validator = ...
// module.exports.validate = ...
let named_validator_export = generate_named_validator_export(
typegen_fragment,
schema,
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1328fc1

Please sign in to comment.