Skip to content

Commit

Permalink
Rename Phase4 -> Compat, make it default
Browse files Browse the repository at this point in the history
Summary:
This changes the name and the default value typegen phase.

The new name is `Compat` - as it exports both new (correct types) and "old" types for operations:

```
export type InternAppQueryVariables = InternAppQuery$variables;
export type InternAppQuery$data = {|
  +node: ?{|
    +$fragmentSpreads: Component_user1$fragmentType & CommonComponent_fragment$fragmentType & PageComponent_user$fragmentType,
  |},
|};
export type InternAppQueryResponse = InternAppQuery$data;
export type InternAppQuery = {|
  variables: InternAppQueryVariables,
  response: InternAppQuery$data,
|};
*/
```

See `InternAppQueryVariables`  and `InternAppQuery`.

This should reduce some issues when updating to V13. See: #3679

Reviewed By: kassens

Differential Revision: D33338628

fbshipit-source-id: 31a22c7c14ff28fcb9236fef83d1bbd51fa65c86
  • Loading branch information
alunyov authored and facebook-github-bot committed Dec 28, 2021
1 parent b450cee commit 4109d4a
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
13 changes: 7 additions & 6 deletions compiler/crates/relay-config/src/typegen_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ impl Default for FlowTypegenConfig {
fn default() -> Self {
Self {
no_future_proof_enums: false,
phase: FlowTypegenPhase::Final,
phase: FlowTypegenPhase::Compat,
rollout: Rollout::default(),
}
}
Expand All @@ -120,11 +120,12 @@ impl FlowTypegenConfig {

#[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)]
pub enum FlowTypegenPhase {
/// - remove $fragmentRefs for spreads
/// - remove $refType from Frag$data
Phase4,
/// Final state
Final,
/// - remove $fragmentRefs for spreads
/// - remove $refType from Frag$data
/// - keep exporting old types for operations
Compat,
}

impl FlowTypegenPhase {
Expand All @@ -133,8 +134,8 @@ impl FlowTypegenPhase {
fn previous(self) -> Self {
use FlowTypegenPhase::*;
match self {
Phase4 => Phase4,
Final => Phase4,
Final => Compat,
Compat => Compat,
}
}
}
2 changes: 1 addition & 1 deletion compiler/crates/relay-typegen/src/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ impl Writer for FlowPrinter {

fn write_export_fragment_type(&mut self, old_name: &str, new_name: &str) -> FmtResult {
match self.flow_typegen_phase {
FlowTypegenPhase::Phase4 => {
FlowTypegenPhase::Compat => {
writeln!(
&mut self.result,
"declare export opaque type {new_name}: FragmentType;
Expand Down
8 changes: 4 additions & 4 deletions compiler/crates/relay-typegen/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ impl<'a> TypeGenerator<'a> {
self.write_input_object_types()?;

match self.flow_typegen_phase {
FlowTypegenPhase::Phase4 => {
FlowTypegenPhase::Compat => {
let new_variables_identifier = format!("{}$variables", typegen_operation.name.item);
self.writer
.write_export_type(&new_variables_identifier, &input_variables_type)?;
Expand All @@ -269,7 +269,7 @@ impl<'a> TypeGenerator<'a> {
}

let response_identifier = match self.flow_typegen_phase {
FlowTypegenPhase::Phase4 => {
FlowTypegenPhase::Compat => {
let new_response_identifier = format!("{}$data", typegen_operation.name.item);
let old_response_identifier = format!("{}Response", typegen_operation.name.item);
self.writer
Expand All @@ -289,7 +289,7 @@ impl<'a> TypeGenerator<'a> {
};

match self.flow_typegen_phase {
FlowTypegenPhase::Phase4 => {
FlowTypegenPhase::Compat => {
let mut operation_types = vec![
Prop::KeyValuePair(KeyValuePairProp {
key: *VARIABLES,
Expand Down Expand Up @@ -494,7 +494,7 @@ impl<'a> TypeGenerator<'a> {
}

match self.flow_typegen_phase {
FlowTypegenPhase::Phase4 => {
FlowTypegenPhase::Compat => {
self.writer.write_export_type(&data_type_name, &type_)?;
self.writer.write_export_type(
data_type.lookup(),
Expand Down
8 changes: 6 additions & 2 deletions compiler/crates/relay-typegen/tests/generate_flow/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ use graphql_syntax::parse_executable;
use indexmap::IndexMap;
use intern::string_key::Intern;
use relay_codegen::JsModuleFormat;
use relay_config::ProjectConfig;
use relay_config::{FlowTypegenConfig, ProjectConfig};
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::apply_transforms;
use relay_typegen::{self, TypegenConfig, TypegenLanguage};
use relay_typegen::{self, FlowTypegenPhase, TypegenConfig, TypegenLanguage};
use std::sync::Arc;

type FnvIndexMap<K, V> = IndexMap<K, V, FnvBuildHasher>;
Expand Down Expand Up @@ -70,6 +70,10 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let typegen_config = TypegenConfig {
language: TypegenLanguage::Flow,
custom_scalar_types,
flow_typegen: FlowTypegenConfig {
phase: FlowTypegenPhase::Final,
..Default::default()
},
..Default::default()
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ use graphql_ir::{build, Program};
use graphql_syntax::parse_executable;
use intern::string_key::Intern;
use relay_codegen::JsModuleFormat;
use relay_config::ProjectConfig;
use relay_config::{FlowTypegenConfig, ProjectConfig};
use relay_test_schema::{get_test_schema, get_test_schema_with_extensions};
use relay_transforms::apply_transforms;
use relay_typegen::{self, TypegenConfig, TypegenLanguage};
use relay_typegen::{self, FlowTypegenPhase, TypegenConfig, TypegenLanguage};
use std::sync::Arc;

pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
Expand Down Expand Up @@ -54,6 +54,10 @@ pub fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let has_unified_output = false;
let typegen_config = TypegenConfig {
language: TypegenLanguage::TypeScript,
flow_typegen: FlowTypegenConfig {
phase: FlowTypegenPhase::Final,
..Default::default()
},
..Default::default()
};

Expand Down

0 comments on commit 4109d4a

Please sign in to comment.