diff --git a/compiler/crates/relay-compiler/src/artifact_content/content.rs b/compiler/crates/relay-compiler/src/artifact_content/content.rs index 36f76ddba6d50..9bfe7515c79e7 100644 --- a/compiler/crates/relay-compiler/src/artifact_content/content.rs +++ b/compiler/crates/relay-compiler/src/artifact_content/content.rs @@ -519,6 +519,7 @@ pub fn generate_fragment( project_config, schema, typegen_fragment, + source_hash, skip_types, fragment_locations, ) @@ -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, FmtError> { @@ -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, diff --git a/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_node.graphql.js b/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_node.graphql.js index 047d714c8fd75..f5ad5e797f6bd 100644 --- a/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_node.graphql.js +++ b/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_node.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<53b3b22d71f7629f39c4f4603c4586ff>> + * @generated SignedSource<<3d2291db4ba78ef6b4b4c6638c9e5bef>> * @flow * @lightSyntaxTransform * @nogrep @@ -21,6 +21,14 @@ import type { FragmentType } from "relay-runtime"; declare export opaque type readUpdatableQueryTest_node$fragmentType: FragmentType; */ +var node/*: any*/ = {}; + +if (__DEV__) { + (node/*: any*/).hash = "1e10d6074f00480fc34548623674b3da"; +} + +module.exports = node; + module.exports.validate = function validate(value/*: { +__id: string, +__isreadUpdatableQueryTest_node?: string, diff --git a/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_user.graphql.js b/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_user.graphql.js index 9dcac1e2e1fac..dc0d5f6ed8e23 100644 --- a/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_user.graphql.js +++ b/packages/relay-runtime/mutations/__tests__/__generated__/readUpdatableQueryTest_user.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<> + * @generated SignedSource<> * @flow * @lightSyntaxTransform * @nogrep @@ -21,6 +21,14 @@ import type { FragmentType } from "relay-runtime"; declare export opaque type readUpdatableQueryTest_user$fragmentType: FragmentType; */ +var node/*: any*/ = {}; + +if (__DEV__) { + (node/*: any*/).hash = "b4c3265697d01e4f38a505ed5bb58bf7"; +} + +module.exports = node; + module.exports.validate = function validate(value/*: { +__typename: string, +__id: string,