Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
21c09e0
Fix remaining cases with hardcoded output, rather than using AST.
MaartenStaa Oct 17, 2020
18ad028
Reduce code duplication for writing AST.
MaartenStaa Oct 17, 2020
c95f333
Fix some typescript tests using Flow typing instead.
MaartenStaa Oct 17, 2020
fac60f0
Allow opting into `import type` syntax for Typescript through config.
MaartenStaa Oct 17, 2020
42fd9e2
Bring format of fragment usage, imports & exports in line with curren…
MaartenStaa Oct 21, 2020
c6150b0
For typescript, use the field name " $data" rather than "$data".
MaartenStaa Oct 24, 2020
555ac15
Handle Windows-style newlines in GraphQL lexing (\r\n).
MaartenStaa Oct 24, 2020
213bf99
Fix grouped fragment refs.
MaartenStaa Oct 24, 2020
d6575ba
Type optional and nullable fields the same as relay-compiler-language…
MaartenStaa Oct 25, 2020
7eaef79
Rename AST::OtherEnumValue to AST::OtherTypename to reflect usage mor…
MaartenStaa Oct 30, 2020
16a642a
Merge remote-tracking branch 'upstream/master' into refine-typescript…
MaartenStaa Oct 30, 2020
6483808
Create AST for type definition when not using haste.
MaartenStaa Oct 30, 2020
f0f3ed8
Don't use relative import path in haste mode.
MaartenStaa Oct 31, 2020
b0c97bf
Allow opting out of future proof enums.
MaartenStaa Oct 31, 2020
0e04a86
Add better support for abstract types (unions and interfaces), using …
MaartenStaa Nov 1, 2020
7275cf7
Handle %other for unions, to be sure the accompanying comment is incl…
MaartenStaa Nov 1, 2020
75a9a26
Some suggestions from Clippy.
MaartenStaa Nov 1, 2020
cc85020
Merge remote-tracking branch 'upstream/master' into better-support-fo…
MaartenStaa Dec 1, 2020
20c443a
Update test fixtures including combinations of different values of fu…
MaartenStaa Dec 1, 2020
69e2811
s/babel/ast
MaartenStaa Dec 27, 2020
8d19116
Fix incorrect merge/rebase: don't use intermediate String for writing…
MaartenStaa Dec 27, 2020
455d3de
Wrap nullable intersections in parentheses as well as unions.
MaartenStaa Dec 27, 2020
c28af7b
Prevent intersections of exact objects, which would not make sense.
MaartenStaa Dec 27, 2020
573d12d
Either list possible type names or "%other", but not a combination of…
MaartenStaa Dec 27, 2020
a125a39
Prevent combinational test fixture output.
MaartenStaa Dec 27, 2020
d769f2a
Add an optional JSON header to typegen fixtures for customizable type…
MaartenStaa Dec 27, 2020
ba2d375
Remove outdated #[allow] attribute.
MaartenStaa Dec 27, 2020
7317056
Merge remote-tracking branch 'upstream/master' into better-support-fo…
MaartenStaa Dec 27, 2020
09ca96b
Revert "remove unused intersection variant"
MaartenStaa Dec 27, 2020
026ab4c
Merge remote-tracking branch 'upstream/master' into better-support-fo…
Oct 19, 2021
5ebfe4d
Update usage after merge of master.
Oct 19, 2021
2070f23
Merge remote-tracking branch 'upstream/main' into better-support-for-…
Oct 19, 2021
853ac17
Fix unused enum variant: FragmentReferenceType.
Oct 19, 2021
3380f23
Merge remote-tracking branch 'upstream/main' into better-support-for-…
Jan 13, 2022
191b4ab
Fix typegen config not being set correctly in typegen tests.
Feb 14, 2022
18ad43e
Fix properties being duplicated in typegen.
Feb 14, 2022
0f9360b
Allow excluding types from future proofness.
Feb 14, 2022
a3cb206
Add Flow version of added test.
Feb 14, 2022
9386f81
Merge remote-tracking branch 'upstream/main' into better-support-for-…
Feb 14, 2022
af6e762
Fix mistake in merge.
Feb 14, 2022
90e6d24
Remove commented out code.
Feb 16, 2022
5185095
Combination of four diffs
rbalicki2 Feb 25, 2022
e4e4c92
Sort enum members.
Feb 26, 2022
c671d16
Sort fragment refs.
Feb 26, 2022
6f4e49f
Only wrap unions & intersections if needed.
Feb 26, 2022
dbbfc3f
Impl Ord for AST in typegen, sort all unions and intersections.
Mar 2, 2022
ea9ee4e
Merge remote-tracking branch 'upstream/main' into typegen-sorting-and…
Mar 2, 2022
e278990
Fix impl Writer for TypeScript: supports_exact_objects is false.
Mar 8, 2022
b3f8072
Remove AST::Intersection from typegen, as it will not be needed.
Mar 9, 2022
bb96fa9
Merge branch 'typegen-sorting-and-wrapping' into better-support-for-a…
Mar 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
6 changes: 4 additions & 2 deletions compiler/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 6 additions & 2 deletions compiler/crates/relay-compiler/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,11 @@ impl fmt::Debug for Config {
} = self;

fn option_fn_to_string<T>(option: &Option<T>) -> &'static str {
if option.is_some() { "Some(Fn)" } else { "None" }
if option.is_some() {
"Some(Fn)"
} else {
"None"
}
}

f.debug_struct("Config")
Expand Down Expand Up @@ -745,8 +749,8 @@ impl SingleProjectConfigFile {
language: self.language.unwrap_or(TypegenLanguage::TypeScript),
custom_scalar_types: self.custom_scalars.clone(),
eager_es_modules: self.eager_es_modules,
future_proof_enums: !self.no_future_proof_enums,
flow_typegen: FlowTypegenConfig {
no_future_proof_enums: self.no_future_proof_enums,
phase: self.typegen_phase,
..Default::default()
},
Expand Down
70 changes: 61 additions & 9 deletions compiler/crates/relay-config/src/typegen_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ impl Default for TypegenLanguage {
}
}

#[derive(Debug, Serialize, Deserialize, Default)]
#[derive(Debug, Serialize, Deserialize)]
#[serde(deny_unknown_fields, rename_all = "camelCase")]
pub struct TypegenConfig {
/// The desired output language, "flow" or "typescript".
Expand Down Expand Up @@ -62,6 +62,23 @@ pub struct TypegenConfig {
#[serde(default)]
pub use_import_type_syntax: bool,

/// 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 = "default_future_proofness")]
pub future_proof_enums: bool,

/// Whether to future proof union and interface types by including "%other" as a possible type.
#[serde(default = "default_future_proofness")]
pub future_proof_abstract_types: bool,

/// For which types (unions or interfaces) to not write out all possible type names if future
/// proof abstract types is set to false. Especially useful for interfaces or unions that may
/// have a lot of concrete types, such as Node.
#[serde(default)]
pub exclude_from_typename_unions: Vec<StringKey>,

/// A map from GraphQL scalar types to a custom JS type, example:
/// { "Url": "String" }
#[serde(default)]
Expand All @@ -79,18 +96,17 @@ pub struct TypegenConfig {
/// This option enables emitting es modules artifacts.
#[serde(default)]
pub eager_es_modules: bool,

/// This option controls which emitted files have sorted fields, fragment names,
/// and union members. It also controls whether unions with more than one element
/// are written with surrounding parentheses.
#[serde(default)]
pub sort_typegen_items: SortTypegenItemsConfig,
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
#[serde(deny_unknown_fields, tag = "phase")]
pub struct FlowTypegenConfig {
/// 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)]
pub no_future_proof_enums: bool,

pub phase: FlowTypegenPhase,
#[serde(default)]
pub rollout: Rollout,
Expand All @@ -99,7 +115,6 @@ pub struct FlowTypegenConfig {
impl Default for FlowTypegenConfig {
fn default() -> Self {
Self {
no_future_proof_enums: false,
phase: FlowTypegenPhase::Final,
rollout: Rollout::default(),
}
Expand Down Expand Up @@ -139,3 +154,40 @@ impl FlowTypegenPhase {
}
}
}

// Custom impl for Default to set future proofness to true when using Default::default().
impl Default for TypegenConfig {
fn default() -> Self {
Self {
language: TypegenLanguage::default(),
enum_module_suffix: None,
optional_input_fields: vec![],
use_import_type_syntax: false,
future_proof_abstract_types: default_future_proofness(),
future_proof_enums: default_future_proofness(),
exclude_from_typename_unions: vec![],
custom_scalar_types: FnvIndexMap::default(),
flow_enums: FnvIndexSet::default(),
require_custom_scalar_types: false,
flow_typegen: FlowTypegenConfig::default(),
eager_es_modules: false,
sort_typegen_items: SortTypegenItemsConfig::default(),
}
}
}

fn default_future_proofness() -> bool {
true
}

#[derive(Debug, Serialize, Deserialize, Clone, Copy, Default)]
pub struct SortTypegenItemsConfig {
#[serde(default)]
pub rollout: Rollout,
}

impl SortTypegenItemsConfig {
pub fn should_sort(&self, rollout_key: StringKey) -> bool {
self.rollout.check(rollout_key.lookup())
}
}
2 changes: 2 additions & 0 deletions compiler/crates/relay-typegen/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ lazy_static = "1.0"
relay-config = { path = "../relay-config" }
relay-transforms = { path = "../relay-transforms" }
schema = { path = "../schema" }
serde = { version = "=1.0.126", features = ["derive", "rc"] }
serde_json = "1.0.68"

[dev-dependencies]
fixture-tests = { path = "../fixture-tests" }
Expand Down
Loading