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 conditional sub-selections in raw response type #4774

Open
wants to merge 1 commit 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
59 changes: 45 additions & 14 deletions compiler/crates/relay-typegen/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1284,6 +1284,38 @@ fn visit_scalar_field(
}));
}

#[allow(clippy::too_many_arguments)]
fn raw_response_visit_condition(
typegen_context: &'_ TypegenContext<'_>,
type_selections: &mut Vec<TypeSelection>,
condition: &Condition,
encountered_enums: &mut EncounteredEnums,
match_fields: &mut MatchFields,
encountered_fragments: &mut EncounteredFragments,
imported_raw_response_types: &mut ImportedRawResponseTypes,
runtime_imports: &mut RuntimeImports,
custom_scalars: &mut CustomScalarsImports,
enclosing_linked_field_concrete_type: Option<Type>,
emit_semantic_types: bool,
) {
let mut selections = raw_response_visit_selections(
typegen_context,
&condition.selections,
encountered_enums,
match_fields,
encountered_fragments,
imported_raw_response_types,
runtime_imports,
custom_scalars,
enclosing_linked_field_concrete_type,
emit_semantic_types,
);
for selection in selections.iter_mut() {
selection.set_conditional(true);
}
type_selections.append(&mut selections);
}

#[allow(clippy::too_many_arguments)]
fn visit_condition(
typegen_context: &'_ TypegenContext<'_>,
Expand Down Expand Up @@ -2327,20 +2359,19 @@ pub(crate) fn raw_response_visit_selections(
enclosing_linked_field_concrete_type,
emit_semantic_types,
),
Selection::Condition(condition) => {
type_selections.extend(raw_response_visit_selections(
typegen_context,
&condition.selections,
encountered_enums,
match_fields,
encountered_fragments,
imported_raw_response_types,
runtime_imports,
custom_scalars,
enclosing_linked_field_concrete_type,
emit_semantic_types,
));
}
Selection::Condition(condition) => raw_response_visit_condition(
typegen_context,
&mut type_selections,
condition,
encountered_enums,
match_fields,
encountered_fragments,
imported_raw_response_types,
runtime_imports,
custom_scalars,
enclosing_linked_field_concrete_type,
emit_semantic_types,
),
}
}
type_selections
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export type ExampleQuery$data = {|
export type ExampleQuery$rawResponse = {|
+node: ?({|
+__typename: "User",
+feedback: ?{|
+feedback?: ?{|
tobias-tengler marked this conversation as resolved.
Show resolved Hide resolved
+id: string,
+name: ?string,
|},
+id: string,
+lastName: ?string,
+name: ?string,
+lastName?: ?string,
+name?: ?string,
|} | {|
+__typename: string,
+id: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ export type ExampleQuery$data = {
export type ExampleQuery$rawResponse = {
readonly node: {
readonly __typename: "User";
readonly feedback: {
readonly feedback?: {
readonly id: string;
readonly name: string | null | undefined;
} | null | undefined;
readonly id: string;
readonly lastName: string | null | undefined;
readonly name: string | null | undefined;
readonly lastName?: string | null | undefined;
readonly name?: string | null | undefined;
} | {
readonly __typename: string;
readonly id: string;
Expand Down

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

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

Loading