Skip to content

Commit

Permalink
Persist flow changes to support overriding the schema to distillery
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D51770906

fbshipit-source-id: 3dbee60a1a98d87059582e03f5ded3b24c167861
  • Loading branch information
Deepak Singh authored and facebook-github-bot committed Jan 31, 2024
1 parent f53a932 commit 8fa540a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ pub async fn persist_operations(
ref text,
ref mut id_and_text_hash,
ref reader_operation,
ref normalization_operation,
..
} = artifact.content
{
Expand All @@ -62,8 +63,17 @@ pub async fn persist_operations(
None
} else if let Some(text) = text {
let text_hash = md5(text);
let artifact_path = root_dir.join(&artifact.path);
let relative_path = artifact.path.to_owned();
let mut override_schema = None;
if let Some(custom_override_schema_determinator) =
config.custom_override_schema_determinator.as_ref()
{
override_schema = custom_override_schema_determinator(
normalization_operation,
project_config,
);
}
let artifact_path = root_dir.join(&artifact.path);
let extracted_persist_id = if config.repersist_operations {
None
} else {
Expand All @@ -79,6 +89,7 @@ pub async fn persist_operations(
.persist_artifact(ArtifactForPersister {
text,
relative_path,
override_schema,
})
.await
.map(|id| {
Expand Down
3 changes: 2 additions & 1 deletion compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ pub struct Config {
/// in the `apply_transforms(...)`.
pub custom_transforms: Option<CustomTransformsConfig>,
pub custom_override_schema_determinator:
Option<Box<dyn Fn(&OperationDefinition) -> Option<String> + Send + Sync>>,
Option<Box<dyn Fn(&OperationDefinition, &ProjectConfig) -> Option<String> + Send + Sync>>,
pub export_persisted_query_ids_to_file: Option<PathBuf>,

/// The async function is called before the compiler connects to the file
Expand Down Expand Up @@ -1010,6 +1010,7 @@ pub type PersistResult<T> = std::result::Result<T, PersistError>;
pub struct ArtifactForPersister {
pub text: String,
pub relative_path: PathBuf,
pub override_schema: Option<String>,
}

#[async_trait]
Expand Down

0 comments on commit 8fa540a

Please sign in to comment.