Skip to content

Commit

Permalink
Inject changed schema files when loading from saved state
Browse files Browse the repository at this point in the history
Reviewed By: kassens

Differential Revision: D46753491

fbshipit-source-id: 381f9c601cbdcd11b336cc45eb664476a3752542
  • Loading branch information
tyao1 authored and facebook-github-bot committed Jun 21, 2023
1 parent 20ff678 commit 99ce43f
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
8 changes: 8 additions & 0 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ use crate::build_project::artifact_writer::ArtifactFileWriter;
use crate::build_project::artifact_writer::ArtifactWriter;
use crate::build_project::generate_extra_artifacts::GenerateExtraArtifactsFn;
use crate::build_project::AdditionalValidations;
use crate::compiler_state::CompilerState;
use crate::compiler_state::ProjectName;
use crate::compiler_state::ProjectSet;
use crate::errors::ConfigValidationError;
Expand All @@ -77,6 +78,9 @@ type PostArtifactsWriter = Box<
type OperationPersisterCreator =
Box<dyn Fn(&ProjectConfig) -> Option<Box<dyn OperationPersister + Send + Sync>> + Send + Sync>;

type UpdateCompilerStateFromSavedState =
Option<Box<dyn Fn(&mut CompilerState, &Config) + Send + Sync>>;

/// The full compiler config. This is a combination of:
/// - the configuration file
/// - the absolute path to the root of the compiled projects
Expand Down Expand Up @@ -149,6 +153,9 @@ pub struct Config {
/// The async function is called before the compiler connects to the file
/// source.
pub initialize_resources: Option<Box<dyn Fn() + Send + Sync>>,

/// Runs in `try_saved_state` when the compiler state is initialized from saved state.
pub update_compiler_state_from_saved_state: UpdateCompilerStateFromSavedState,
}

pub enum FileSourceKind {
Expand Down Expand Up @@ -410,6 +417,7 @@ Example file:
custom_transforms: None,
export_persisted_query_ids_to_file: None,
initialize_resources: None,
update_compiler_state_from_saved_state: None,
};

let mut validation_errors = Vec::new();
Expand Down
2 changes: 1 addition & 1 deletion compiler/crates/relay-compiler/src/file_source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pub use source_control_update_status::SourceControlUpdateStatus;
pub use watchman_client::prelude::Clock;
use watchman_file_source::WatchmanFileSource;

use self::external_file_source::ExternalFileSourceResult;
pub use self::external_file_source::ExternalFileSourceResult;
pub use self::extract_graphql::extract_javascript_features_from_file;
pub use self::extract_graphql::source_for_location;
pub use self::extract_graphql::FsSourceReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ impl<'config> WatchmanFileSource<'config> {
saved_state_config.clone(),
saved_state_loader.as_ref(),
saved_state_version,
self.config,
)
.await
{
Expand Down Expand Up @@ -241,6 +242,7 @@ impl<'config> WatchmanFileSource<'config> {
saved_state_config: ScmAwareClockData,
saved_state_loader: &'_ (dyn SavedStateLoader + Send + Sync),
saved_state_version: &str,
config: &Config,
) -> std::result::Result<Result<CompilerState>, &'static str> {
let scm_since = Clock::ScmAware(FatClockData {
clock: ClockSpec::null(),
Expand Down Expand Up @@ -296,6 +298,13 @@ impl<'config> WatchmanFileSource<'config> {
.write()
.unwrap()
.push(file_source_result);

if let Some(update_compiler_state_from_saved_state) =
&config.update_compiler_state_from_saved_state
{
update_compiler_state_from_saved_state(&mut compiler_state, config);
}

if let Err(parse_error) = perf_logger_event.time("merge_file_source_changes", || {
compiler_state.merge_file_source_changes(self.config, perf_logger, true)
}) {
Expand Down
2 changes: 2 additions & 0 deletions compiler/crates/relay-compiler/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ pub use config::ProjectConfig;
pub use config::RemotePersistConfig;
pub use config::SchemaLocation;
pub use file_source::source_for_location;
pub use file_source::ExternalFileSourceResult;
pub use file_source::File;
pub use file_source::FileCategorizer;
pub use file_source::FileGroup;
pub use file_source::FileSource;
Expand Down

0 comments on commit 99ce43f

Please sign in to comment.