Skip to content

Commit 8fa540a

Browse files
Deepak Singhfacebook-github-bot
authored andcommitted
Persist flow changes to support overriding the schema to distillery
Reviewed By: tyao1 Differential Revision: D51770906 fbshipit-source-id: 3dbee60a1a98d87059582e03f5ded3b24c167861
1 parent f53a932 commit 8fa540a

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

compiler/crates/relay-compiler/src/build_project/persist_operations.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ pub async fn persist_operations(
4848
ref text,
4949
ref mut id_and_text_hash,
5050
ref reader_operation,
51+
ref normalization_operation,
5152
..
5253
} = artifact.content
5354
{
@@ -62,8 +63,17 @@ pub async fn persist_operations(
6263
None
6364
} else if let Some(text) = text {
6465
let text_hash = md5(text);
65-
let artifact_path = root_dir.join(&artifact.path);
6666
let relative_path = artifact.path.to_owned();
67+
let mut override_schema = None;
68+
if let Some(custom_override_schema_determinator) =
69+
config.custom_override_schema_determinator.as_ref()
70+
{
71+
override_schema = custom_override_schema_determinator(
72+
normalization_operation,
73+
project_config,
74+
);
75+
}
76+
let artifact_path = root_dir.join(&artifact.path);
6777
let extracted_persist_id = if config.repersist_operations {
6878
None
6979
} else {
@@ -79,6 +89,7 @@ pub async fn persist_operations(
7989
.persist_artifact(ArtifactForPersister {
8090
text,
8191
relative_path,
92+
override_schema,
8293
})
8394
.await
8495
.map(|id| {

compiler/crates/relay-compiler/src/config.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ pub struct Config {
149149
/// in the `apply_transforms(...)`.
150150
pub custom_transforms: Option<CustomTransformsConfig>,
151151
pub custom_override_schema_determinator:
152-
Option<Box<dyn Fn(&OperationDefinition) -> Option<String> + Send + Sync>>,
152+
Option<Box<dyn Fn(&OperationDefinition, &ProjectConfig) -> Option<String> + Send + Sync>>,
153153
pub export_persisted_query_ids_to_file: Option<PathBuf>,
154154

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

10151016
#[async_trait]

0 commit comments

Comments
 (0)