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

Fix raw response with selections on abstract type #4775

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -158,6 +158,11 @@ pub struct FeatureFlags {
/// ```
#[serde(default)]
pub disable_deduping_common_structures_in_artifacts: FeatureFlag,

/// Disable the generation of a more precise raw response type
/// for selections on abstract types.
#[serde(default)]
pub disable_more_precise_abstract_selection_raw_response_type: FeatureFlag,
}

#[derive(Debug, Deserialize, Clone, Serialize, Default, JsonSchema)]
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 @@ -798,6 +798,92 @@
}
]
},
"disable_more_precise_abstract_selection_raw_response_type": {
"description": "Disable the generation of a more precise raw response type for selections on abstract types.",
"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
}
}
}
]
},
"disable_resolver_reader_ast": {
"description": "Mirror of `enable_resolver_normalization_ast` excludes resolver metadata from reader ast",
"default": false,
Expand Down Expand Up @@ -1979,6 +2065,9 @@
"disable_full_argument_type_validation": {
"kind": "disabled"
},
"disable_more_precise_abstract_selection_raw_response_type": {
"kind": "disabled"
},
"disable_resolver_reader_ast": false,
"disable_schema_validation": false,
"enable_3d_branch_arg_generation": false,
Expand Down Expand Up @@ -2699,6 +2788,92 @@
}
]
},
"disable_more_precise_abstract_selection_raw_response_type": {
"description": "Disable the generation of a more precise raw response type for selections on abstract types.",
"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
}
}
}
]
},
"disable_resolver_reader_ast": {
"description": "Mirror of `enable_resolver_normalization_ast` excludes resolver metadata from reader ast",
"default": false,
Expand Down Expand Up @@ -4248,6 +4423,92 @@
}
]
},
"disable_more_precise_abstract_selection_raw_response_type": {
"description": "Disable the generation of a more precise raw response type for selections on abstract types.",
"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
}
}
}
]
},
"disable_resolver_reader_ast": {
"description": "Mirror of `enable_resolver_normalization_ast` excludes resolver metadata from reader ast",
"default": false,
Expand Down
28 changes: 28 additions & 0 deletions compiler/crates/relay-typegen/src/type_selection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,17 @@ impl TypeSelection {
}
}

pub(crate) fn set_abstract_type(&mut self, type_: Type) {
match self {
TypeSelection::LinkedField(l) => l.abstract_type = Some(type_),
TypeSelection::ScalarField(s) => s.abstract_type = Some(type_),
TypeSelection::InlineFragment(f) => f.abstract_type = Some(type_),
TypeSelection::FragmentSpread(f) => f.abstract_type = Some(type_),
TypeSelection::ModuleDirective(m) => m.abstract_type = Some(type_),
TypeSelection::RawResponseFragmentSpread(f) => f.abstract_type = Some(type_),
}
}

pub(crate) fn set_conditional(&mut self, conditional: bool) {
match self {
TypeSelection::LinkedField(l) => l.conditional = conditional,
Expand Down Expand Up @@ -75,6 +86,17 @@ impl TypeSelection {
}
}

pub(crate) fn get_enclosing_abstract_type(&self) -> Option<Type> {
match self {
TypeSelection::LinkedField(l) => l.abstract_type,
TypeSelection::ScalarField(s) => s.abstract_type,
TypeSelection::FragmentSpread(f) => f.abstract_type,
TypeSelection::InlineFragment(f) => f.abstract_type,
TypeSelection::ModuleDirective(m) => m.abstract_type,
TypeSelection::RawResponseFragmentSpread(f) => f.abstract_type,
}
}

pub(crate) fn is_typename(&self) -> bool {
matches!(
self,
Expand Down Expand Up @@ -120,6 +142,7 @@ pub(crate) struct RawResponseFragmentSpread {
pub(crate) value: StringKey,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
}

#[derive(Debug, Clone)]
Expand All @@ -128,6 +151,7 @@ pub(crate) struct ModuleDirective {
pub(crate) document_name: StringKey,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
}

#[derive(Debug, Clone)]
Expand All @@ -137,6 +161,7 @@ pub(crate) struct TypeSelectionLinkedField {
pub(crate) node_selections: TypeSelectionMap,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
pub(crate) is_result_type: bool,
}

Expand All @@ -147,6 +172,7 @@ pub(crate) struct TypeSelectionScalarField {
pub(crate) value: AST,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
pub(crate) is_result_type: bool,
}

Expand All @@ -155,13 +181,15 @@ pub(crate) struct TypeSelectionInlineFragment {
pub(crate) fragment_name: FragmentDefinitionName,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
}

#[derive(Debug, Clone)]
pub(crate) struct TypeSelectionFragmentSpread {
pub(crate) fragment_name: FragmentDefinitionName,
pub(crate) conditional: bool,
pub(crate) concrete_type: Option<Type>,
pub(crate) abstract_type: Option<Type>,
// Why are we using TypeSelectionInfo instead of re-using concrete_type?
// Because concrete_type is poorly named and does not refer to the concrete
// type of the fragment spread.
Expand Down
Loading
Loading