Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable checking Typescript files behind a compiler flag #4753

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Move compiler config to feature flag, update tests
  • Loading branch information
Drew Atkinson committed Jul 31, 2024
commit 4978898210658df5aae0e1586b6c2fc27902d5f3
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 @@ -124,6 +124,10 @@ pub struct FeatureFlags {
/// Disable validation of the `edgeTypeName` argument on `@prependNode` and `@appendNode`.
#[serde(default)]
pub disable_edge_type_name_validation_on_declerative_connection_directives: FeatureFlag,

// Removes the @ts-nocheck pragma from generated Typescript Files
#[serde(default)]
pub typescript_check_generated_files: bool,
}

#[derive(Debug, Deserialize, Clone, Serialize, Default, JsonSchema)]
Expand Down
23 changes: 14 additions & 9 deletions compiler/crates/relay-compiler/relay-compiler-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,10 @@
}
}
]
},
"typescript_check_generated_files": {
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1672,10 +1676,6 @@
"description": "Added in 13.1.1 to customize Final/Compat mode in the single project config file Removed in 14.0.0",
"default": null
},
"typescriptCheckGeneratedFiles": {
"default": false,
"type": "boolean"
},
"typescriptExcludeUndefinedFromNullableUnion": {
"description": "Keep the previous compiler behavior by outputting an union of the raw type and null, and not the **correct** behavior of an union with the raw type, null and undefined.",
"default": false,
Expand Down Expand Up @@ -1774,7 +1774,8 @@
},
"text_artifacts": {
"kind": "disabled"
}
},
"typescript_check_generated_files": false
},
"type": "object",
"properties": {
Expand Down Expand Up @@ -2939,6 +2940,10 @@
}
}
]
},
"typescript_check_generated_files": {
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -4307,6 +4312,10 @@
}
}
]
},
"typescript_check_generated_files": {
"default": false,
"type": "boolean"
}
},
"additionalProperties": false
Expand Down Expand Up @@ -4730,10 +4739,6 @@
"null"
]
},
"typescriptCheckGeneratedFiles": {
"default": false,
"type": "boolean"
},
"typescriptExcludeUndefinedFromNullableUnion": {
"description": "Keep the previous compiler behavior by outputting an union of the raw type and null, and not the **correct** behavior of an union with the raw type, null and undefined.",
"default": false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ fn generate_disable_lint_section(project_config: &ProjectConfig) -> Result<Gener
TypegenLanguage::TypeScript => {
writeln!(section, "/* tslint:disable */")?;
writeln!(section, "/* eslint-disable */")?;
if !project_config.typegen_config.typescript_check_generated_files {
if !project_config.feature_flags.typescript_check_generated_files {
writeln!(section, "// @ts-nocheck")?;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ use relay_test_schema::get_test_schema_with_custom_id;
use relay_test_schema::get_test_schema_with_custom_id_with_extensions;
use relay_transforms::apply_transforms;
use relay_transforms::DIRECTIVE_SPLIT_OPERATION;
use relay_typegen::TypegenConfig;

pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String> {
let source_location = SourceLocationKey::standalone(fixture.file_name);
Expand Down Expand Up @@ -109,10 +108,6 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
.unwrap_or(default_schema_config.node_interface_id_variable_name),
..default_schema_config
},
typegen_config: TypegenConfig {
typescript_check_generated_files: true,
..Default::default()
},
js_module_format: JsModuleFormat::Haste,
..Default::default()
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ graphql`
"language": "typescript",
"schema": "./schema.graphql",
"featureFlags": {
"enable_fragment_argument_transform": true
},
"typescriptCheckGeneratedFiles": true
"enable_fragment_argument_transform": true,
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ graphql`
"language": "typescript",
"schema": "./schema.graphql",
"featureFlags": {
"enable_fragment_argument_transform": true
},
"typescriptCheckGeneratedFiles": true
"enable_fragment_argument_transform": true,
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ graphql`
"persistConfig": {
"file": "./operations.json"
},
"typescriptCheckGeneratedFiles": true
"featureFlags": {
"typescript_check_generated_files": true
}
}

//- operations.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ graphql`
"persistConfig": {
"file": "./operations.json"
},
"typescriptCheckGeneratedFiles": true
"featureFlags": {
"typescript_check_generated_files": true
}
}

//- operations.json
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ graphql`
{
"language": "typescript",
"schema": "./schema.graphql",
"typescriptCheckGeneratedFiles": true
"featureFlags": {
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ graphql`
{
"language": "typescript",
"schema": "./schema.graphql",
"typescriptCheckGeneratedFiles": true
"featureFlags": {
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@ graphql`fragment barFragment on User {
"schema": "./schema.graphql",
"eagerEsModules": true,
"featureFlags": {
"enable_relay_resolver_transform": true
},
"typescriptCheckGeneratedFiles": true
"enable_relay_resolver_transform": true,
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ graphql`fragment barFragment on User {
"schema": "./schema.graphql",
"eagerEsModules": true,
"featureFlags": {
"enable_relay_resolver_transform": true
},
"typescriptCheckGeneratedFiles": true
"enable_relay_resolver_transform": true,
"typescript_check_generated_files": true
}
}

//- schema.graphql
Expand Down
5 changes: 0 additions & 5 deletions compiler/crates/relay-config/src/typegen_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,6 @@ pub struct TypegenConfig {
#[serde(default)]
pub typescript_exclude_undefined_from_nullable_union: bool,

// todo: should this go here or in a feature flag? Above flag is discussed here: https://github.com/facebook/relay/pull/4380
#[serde(default)]
pub typescript_check_generated_files: bool,

/// EXPERIMENTAL: If your environment is configured to handles errors out of band, either via
/// a network layer which discards responses with errors, or via enabling strict
/// error handling in the runtime, you can enable this flag to have Relay generate
Expand Down Expand Up @@ -149,7 +145,6 @@ impl Default for TypegenConfig {
typescript_exclude_undefined_from_nullable_union: Default::default(),
experimental_emit_semantic_nullability_types: Default::default(),
custom_error_type: None,
typescript_check_generated_files: Default::default(),
}
}
}