Skip to content

Commit

Permalink
No future proof enums
Browse files Browse the repository at this point in the history
Reviewed By: tyao1

Differential Revision: D32211424

fbshipit-source-id: bc9266fd0015c0e9743c7d92b59cdbd6e8fea65e
  • Loading branch information
alunyov authored and facebook-github-bot committed Nov 5, 2021
1 parent f557a9f commit dc74f42
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
6 changes: 5 additions & 1 deletion compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ use rayon::prelude::*;
use regex::Regex;
use relay_codegen::JsModuleFormat;
use relay_transforms::ConnectionInterface;
use relay_typegen::TypegenConfig;
pub use relay_typegen::TypegenLanguage;
use relay_typegen::{FlowTypegenConfig, TypegenConfig};
use serde::{Deserialize, Serialize};
use sha1::{Digest, Sha1};
use std::path::{Path, PathBuf};
Expand Down Expand Up @@ -700,6 +700,10 @@ impl From<SingleProjectConfigFile> for MultiProjectConfigFile {
typegen_config: TypegenConfig {
language: oss_config.language.unwrap_or(TypegenLanguage::TypeScript),
custom_scalar_types: oss_config.custom_scalars,
flow_typegen: FlowTypegenConfig {
no_future_proof_enums: oss_config.no_future_proof_enums,
..Default::default()
},
..Default::default()
},
..Default::default()
Expand Down
14 changes: 12 additions & 2 deletions compiler/crates/relay-typegen/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,18 +80,28 @@ pub struct TypegenConfig {
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[serde(deny_unknown_fields, tag = "phase")]
pub struct FlowTypegenConfig {
phase: FlowTypegenPhase,
/// This option controls whether or not a catch-all entry is added to enum type definitions
/// for values that may be added in the future. Enabling this means you will have to update
/// your application whenever the GraphQL server schema adds new enum values to prevent it
/// from breaking.
#[serde(default)]
rollout: Rollout,
pub no_future_proof_enums: bool,

pub phase: FlowTypegenPhase,
#[serde(default)]
pub rollout: Rollout,
}

impl Default for FlowTypegenConfig {
fn default() -> Self {
Self {
no_future_proof_enums: false,
phase: FlowTypegenPhase::Old,
rollout: Rollout::default(),
}
}
}

impl FlowTypegenConfig {
/// Returns the FlowTypegenPhase based on the config. If a `Rollout` check
/// is not passing, the previous phase is returned.
Expand Down
8 changes: 6 additions & 2 deletions compiler/crates/relay-typegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::flow::FlowPrinter;
use crate::typescript::TypeScriptPrinter;
use crate::writer::{KeyValuePairProp, SpreadProp, Writer};
use common::NamedItem;
pub use config::{FlowTypegenPhase, TypegenConfig, TypegenLanguage};
pub use config::{FlowTypegenConfig, FlowTypegenPhase, TypegenConfig, TypegenLanguage};
use fnv::FnvHashSet;
use graphql_ir::{
Condition, Directive, FragmentDefinition, FragmentSpread, InlineFragment, LinkedField,
Expand Down Expand Up @@ -1363,7 +1363,11 @@ impl<'a> TypeGenerator<'a> {
.iter()
.map(|enum_value| AST::StringLiteral(enum_value.value))
.collect();
members.push(AST::StringLiteral(*FUTURE_ENUM_VALUE));

if !self.typegen_config.flow_typegen.no_future_proof_enums {
members.push(AST::StringLiteral(*FUTURE_ENUM_VALUE));
}

self.writer
.write_export_type(enum_type.name.lookup(), &AST::Union(members))?;
}
Expand Down

0 comments on commit dc74f42

Please sign in to comment.