Skip to content

Commit

Permalink
Add feature flag for reader AST module imports
Browse files Browse the repository at this point in the history
Summary:
This diff adds a feature flag to turn on generating the `moduleImports` field in the Reader AST. This is necessary as, if records are serialized for caching, the module load function cannot be saved. By keeping it in the Reader AST, any 3D module fields can be looked up at read time rather than from the record. It builds upon the recently completed client 3D work.

This diff adds a feature flag to turn on generating the `moduleImports` field in the Reader AST. It builds upon the recently completed client 3D work.

Reviewed By: tyao1

Differential Revision: D62347343

fbshipit-source-id: 2e9f0635f27c112871b45a2fee5c87ff9235eb2c
  • Loading branch information
evanyeung authored and facebook-github-bot committed Sep 20, 2024
1 parent 55795a1 commit bb30bb6
Show file tree
Hide file tree
Showing 3 changed files with 281 additions and 1 deletion.
5 changes: 5 additions & 0 deletions compiler/crates/common/src/feature_flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,14 @@ pub struct FeatureFlags {
/// This flag will be removed in a future version of Relay.
#[serde(default)]
pub disable_full_argument_type_validation: FeatureFlag,

/// Enable a custom path for artifacts
#[serde(default)]
pub enable_custom_artifacts_path: FeatureFlag,

/// Generate the `moduleImports` field in the Reader AST.
#[serde(default)]
pub use_reader_module_imports: FeatureFlag,
}

#[derive(Debug, Deserialize, Clone, Serialize, Default, JsonSchema)]
Expand Down
16 changes: 15 additions & 1 deletion compiler/crates/relay-codegen/src/build_ast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use std::path::PathBuf;

use common::DirectiveName;
use common::FeatureFlag;
use common::NamedItem;
use common::ObjectName;
use common::WithLocation;
Expand Down Expand Up @@ -2248,9 +2249,22 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> {
fragment_prop_name: Primitive::String(fragment_name_str[underscore_idx + 1..].intern()),
kind: Primitive::String(CODEGEN_CONSTANTS.module_import),
};

let should_use_reader_module_imports =
match &self.project_config.feature_flags.use_reader_module_imports {
FeatureFlag::Enabled => true,
FeatureFlag::Disabled => false,
FeatureFlag::Limited {
allowlist: fragment_names,
} => fragment_names.contains(&module_metadata.key),
FeatureFlag::Rollout { rollout } => {
rollout.check(module_metadata.key.lookup().as_bytes())
}
};

match self.variant {
CodegenVariant::Reader => {
if module_metadata.read_time_resolvers {
if module_metadata.read_time_resolvers || should_use_reader_module_imports {
if let Some(dynamic_module_provider) = self
.project_config
.module_import_config
Expand Down
261 changes: 261 additions & 0 deletions compiler/crates/relay-compiler/relay-compiler-config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -1273,6 +1273,92 @@
}
}
]
},
"use_reader_module_imports": {
"description": "Generate the `moduleImports` field in the Reader AST.",
"default": {
"kind": "disabled"
},
"oneOf": [
{
"description": "Fully disabled: developers may not use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"disabled"
]
}
}
},
{
"description": "Fully enabled: developers may use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"enabled"
]
}
}
},
{
"description": "Partially enabled: developers may only use this feature on the listed items (fragments, fields, types).",
"type": "object",
"required": [
"allowlist",
"kind"
],
"properties": {
"allowlist": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"kind": {
"type": "string",
"enum": [
"limited"
]
}
}
},
{
"description": "Partially enabled: used for gradual rollout of the feature",
"type": "object",
"required": [
"kind",
"rollout"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"rollout"
]
},
"rollout": {
"description": "A utility to enable gradual rollout of large codegen changes. Can be constructed as the Default which passes or a percentage between 0 and 100.",
"type": [
"integer",
"null"
],
"format": "uint8",
"minimum": 0.0
}
}
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -1835,6 +1921,9 @@
},
"text_artifacts": {
"kind": "disabled"
},
"use_reader_module_imports": {
"kind": "disabled"
}
},
"type": "object",
Expand Down Expand Up @@ -3001,6 +3090,92 @@
}
}
]
},
"use_reader_module_imports": {
"description": "Generate the `moduleImports` field in the Reader AST.",
"default": {
"kind": "disabled"
},
"oneOf": [
{
"description": "Fully disabled: developers may not use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"disabled"
]
}
}
},
{
"description": "Fully enabled: developers may use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"enabled"
]
}
}
},
{
"description": "Partially enabled: developers may only use this feature on the listed items (fragments, fields, types).",
"type": "object",
"required": [
"allowlist",
"kind"
],
"properties": {
"allowlist": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"kind": {
"type": "string",
"enum": [
"limited"
]
}
}
},
{
"description": "Partially enabled: used for gradual rollout of the feature",
"type": "object",
"required": [
"kind",
"rollout"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"rollout"
]
},
"rollout": {
"description": "A utility to enable gradual rollout of large codegen changes. Can be constructed as the Default which passes or a percentage between 0 and 100.",
"type": [
"integer",
"null"
],
"format": "uint8",
"minimum": 0.0
}
}
}
]
}
},
"additionalProperties": false
Expand Down Expand Up @@ -4382,6 +4557,92 @@
}
}
]
},
"use_reader_module_imports": {
"description": "Generate the `moduleImports` field in the Reader AST.",
"default": {
"kind": "disabled"
},
"oneOf": [
{
"description": "Fully disabled: developers may not use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"disabled"
]
}
}
},
{
"description": "Fully enabled: developers may use this feature",
"type": "object",
"required": [
"kind"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"enabled"
]
}
}
},
{
"description": "Partially enabled: developers may only use this feature on the listed items (fragments, fields, types).",
"type": "object",
"required": [
"allowlist",
"kind"
],
"properties": {
"allowlist": {
"type": "array",
"items": {
"type": "string"
},
"uniqueItems": true
},
"kind": {
"type": "string",
"enum": [
"limited"
]
}
}
},
{
"description": "Partially enabled: used for gradual rollout of the feature",
"type": "object",
"required": [
"kind",
"rollout"
],
"properties": {
"kind": {
"type": "string",
"enum": [
"rollout"
]
},
"rollout": {
"description": "A utility to enable gradual rollout of large codegen changes. Can be constructed as the Default which passes or a percentage between 0 and 100.",
"type": [
"integer",
"null"
],
"format": "uint8",
"minimum": 0.0
}
}
}
]
}
},
"additionalProperties": false
Expand Down

0 comments on commit bb30bb6

Please sign in to comment.