Skip to content

Commit

Permalink
Add artifact with schema resolvers
Browse files Browse the repository at this point in the history
Reviewed By: alunyov

Differential Revision: D50118100

fbshipit-source-id: 6e7b79b3445ef51de9cb9cc0d4a5533c85310dda
  • Loading branch information
Gerard Moreno-Torres Bertran authored and facebook-github-bot committed Oct 17, 2023
1 parent c4618c6 commit 3d66ad8
Show file tree
Hide file tree
Showing 10 changed files with 25 additions and 13 deletions.
4 changes: 4 additions & 0 deletions compiler/crates/common/src/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ pub struct FeatureFlags {
/// Fully build the normalization AST for Resolvers
#[serde(default)]
pub enable_resolver_normalization_ast: bool,

/// Fully build the schema resolvers artifact
#[serde(default)]
pub enable_schema_resolvers: bool,
}

#[derive(Debug, Deserialize, Clone, Serialize)]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,7 @@ fn write_import_type_from(
}
}

fn write_export_generated_node(
pub fn write_export_generated_node(
typegen_config: &TypegenConfig,
section: &mut dyn Write,
variable_node: &str,
Expand All @@ -846,7 +846,7 @@ fn write_export_generated_node(
}
}

fn generate_docblock_section(
pub fn generate_docblock_section(
config: &Config,
project_config: &ProjectConfig,
extra_annotations: Vec<String>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/crates/relay-compiler/src/artifact_content/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
* LICENSE file in the root directory of this source tree.
*/

mod content;
mod content_section;
pub mod content;
pub mod content_section;

use std::sync::Arc;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@
use schema::SDLSchema;

use super::Artifact;
use super::Config;
use super::Programs;
use super::ProjectConfig;

pub type GenerateExtraArtifactsFn =
Box<dyn Fn(&ProjectConfig, &SDLSchema, &Programs, &[Artifact]) -> Vec<Artifact> + Send + Sync>;
pub type GenerateExtraArtifactsFn = Box<
dyn Fn(&Config, &ProjectConfig, &SDLSchema, &Programs, &[Artifact]) -> Vec<Artifact>
+ Send
+ Sync,
>;
1 change: 1 addition & 0 deletions compiler/crates/relay-compiler/src/build_project/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ pub async fn commit_project(
if let Some(generate_extra_artifacts_fn) = &config.generate_extra_artifacts {
log_event.time("generate_extra_artifacts_time", || {
artifacts.extend(generate_extra_artifacts_fn(
config,
project_config,
schema,
&programs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
enable_resolver_normalization_ast: fixture
.content
.contains("# enable_resolver_normalization_ast"),
enable_schema_resolvers: false,
};

let default_project_config = ProjectConfig {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
relay_resolver_enable_output_type: FeatureFlag::Disabled,
relay_resolver_enable_interface_output_type: FeatureFlag::Disabled,
enable_resolver_normalization_ast: false,
enable_schema_resolvers: false,
};

let default_schema_config = SchemaConfig::default();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ pub fn generate_relay_resolvers_model_fragments(
next_program
}

fn get_resolver_source_hash(field: &schema::Field) -> Option<ResolverSourceHash> {
pub fn get_resolver_source_hash(field: &schema::Field) -> Option<ResolverSourceHash> {
field
.directives
.named(*RELAY_RESOLVER_SOURCE_HASH)
Expand Down
4 changes: 2 additions & 2 deletions compiler/crates/relay-transforms/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ mod fragment_alias_directive;
mod generate_data_driven_dependency_metadata;
mod generate_id_field;
mod generate_live_query_metadata;
mod generate_relay_resolvers_model_fragments;
pub mod generate_relay_resolvers_model_fragments;
mod generate_relay_resolvers_operations_for_nested_objects;
mod generate_typename;
mod handle_fields;
Expand All @@ -47,7 +47,7 @@ mod refetchable_fragment;
mod relay_actor_change;
mod relay_directive;
mod relay_node_identifier;
mod relay_resolvers;
pub mod relay_resolvers;
mod remove_base_fragments;
mod required_directive;
mod root_variables;
Expand Down
9 changes: 5 additions & 4 deletions compiler/crates/relay-transforms/src/relay_resolvers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,16 +617,17 @@ impl Transformer for RelayResolverFieldTransform<'_> {
}
}

struct ResolverInfo {
#[derive(Debug)]
pub struct ResolverInfo {
fragment_name: Option<FragmentDefinitionName>,
fragment_data_injection_mode: Option<FragmentDataInjectionMode>,
import_path: StringKey,
import_name: Option<StringKey>,
pub import_path: StringKey,
pub import_name: Option<StringKey>,
live: bool,
has_output_type: bool,
}

fn get_resolver_info(
pub fn get_resolver_info(
schema: &SDLSchema,
resolver_field: &Field,
error_location: Location,
Expand Down

0 comments on commit 3d66ad8

Please sign in to comment.