Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[relay-compiler] Export node from assignable fragment #4409

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

Loading