Skip to content

Commit

Permalink
Add fb_only feature for subscription/live query transfroms
Browse files Browse the repository at this point in the history
Summary:
Fix for #3703

- These two transforms are fb-specific, they are used when `fb_only` feature is enabled (and this is ON for fb-specific build)
- OSS `relay-compiler` doesn't have this feature

Reviewed By: kassens

Differential Revision: D33341463

fbshipit-source-id: 3d18c70ed5ed40943e1cb2c7c52d62cd715e7edb
  • Loading branch information
alunyov authored and facebook-github-bot committed Dec 29, 2021
1 parent 95f1ed8 commit 18305a1
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 13 deletions.
1 change: 0 additions & 1 deletion compiler/crates/graphql-ir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ common = { path = "../common" }
errors = { path = "../errors" }
fnv = "1.0"
graphql-syntax = { path = "../graphql-syntax" }
indexmap = { version = "1.7.0", features = ["rayon", "serde-1"] }
intern = { path = "../intern" }
lazy_static = "1.0"
once_cell = "1.8"
Expand Down
3 changes: 0 additions & 3 deletions compiler/crates/graphql-ir/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -564,9 +564,6 @@ pub enum ValidationMessage {
#[error("Subscription '{subscription_name}' must have a single selection")]
GenerateSubscriptionNameSingleSelectionItem { subscription_name: StringKey },

#[error("The root of subscription '{subscription_name}' must be a simple selection.")]
GenerateSubscriptionNameSimpleSelection { subscription_name: StringKey },

#[error(
"Live query expects 'polling_interval' or 'config_id' as an argument to @live_query to for root field {query_name}"
)]
Expand Down
4 changes: 4 additions & 0 deletions compiler/crates/relay-transforms/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -122,3 +122,7 @@ fixture-tests = { path = "../fixture-tests" }
graphql-cli = { path = "../graphql-cli" }
graphql-test-helpers = { path = "../graphql-test-helpers" }
relay-test-schema = { path = "../relay-test-schema" }

[features]
default = ["fb_only"]
fb_only = []
37 changes: 31 additions & 6 deletions compiler/crates/relay-transforms/src/apply_transforms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,17 +235,42 @@ fn apply_operation_transforms(
)
})?;

// TODO(T67052528): execute FB-specific transforms only if config options is provided
program = log_event.time("generate_subscription_name_metadata", || {
generate_subscription_name_metadata(&program)
program =
apply_internal_fb_operation_transforms(project_config, &program, Arc::clone(&perf_logger))?;

log_event.complete();

Ok(Arc::new(program))
}

#[cfg(feature = "fb_only")]
fn apply_internal_fb_operation_transforms(
project_config: &ProjectConfig,
program: &Program,
perf_logger: Arc<impl PerfLogger>,
) -> DiagnosticsResult<Program> {
let log_event = perf_logger.create_event("apply_internal_fb_operation_transforms");
log_event.string("project", project_config.name.to_string());

let mut next_program = log_event.time("generate_subscription_name_metadata", || {
generate_subscription_name_metadata(program)
})?;
program = log_event.time("generate_live_query_metadata", || {
generate_live_query_metadata(&program)
next_program = log_event.time("generate_live_query_metadata", || {
generate_live_query_metadata(&next_program)
})?;

log_event.complete();

Ok(Arc::new(program))
Ok(next_program)
}

#[cfg(not(feature = "fb_only"))]
fn apply_internal_fb_operation_transforms(
_project_config: &ProjectConfig,
program: &Program,
_perf_logger: Arc<impl PerfLogger>,
) -> DiagnosticsResult<Program> {
Ok(program.clone())
}

/// After the operation transforms, this applies further transforms that only
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,16 @@ use crate::INTERNAL_METADATA_DIRECTIVE;
use common::{Diagnostic, DiagnosticsResult, WithLocation};
use graphql_ir::{
Argument, ConstantValue, Directive, OperationDefinition, Program, Selection, Transformed,
Transformer, ValidationMessage, Value,
Transformer, Value,
};
use graphql_syntax::OperationKind;
use intern::string_key::{Intern, StringKey};
use lazy_static::lazy_static;
use schema::Schema;
use thiserror::Error;

lazy_static! {
static ref SUBSCRITION_NAME_METADATA_KEY: StringKey = "subscriptionName".intern();
static ref SUBSCRIPTION_NAME_METADATA_KEY: StringKey = "subscriptionName".intern();
}

pub fn generate_subscription_name_metadata(program: &Program) -> DiagnosticsResult<Program> {
Expand Down Expand Up @@ -77,7 +78,7 @@ impl<'s> Transformer for GenerateSubscriptionNameMetadata<'s> {
arguments: vec![Argument {
name: WithLocation::new(
operation.name.location,
*SUBSCRITION_NAME_METADATA_KEY,
*SUBSCRIPTION_NAME_METADATA_KEY,
),
value: WithLocation::new(
operation.name.location,
Expand Down Expand Up @@ -108,3 +109,9 @@ impl<'s> Transformer for GenerateSubscriptionNameMetadata<'s> {
}
}
}

#[derive(Debug, Error)]
pub enum ValidationMessage {
#[error("The root of subscription '{subscription_name}' must be a simple selection.")]
GenerateSubscriptionNameSimpleSelection { subscription_name: StringKey },
}

0 comments on commit 18305a1

Please sign in to comment.