Skip to content

Commit

Permalink
Fix conditional sub-selections in raw response type
Browse files Browse the repository at this point in the history
  • Loading branch information
tobias-tengler committed Aug 20, 2024
1 parent 95f77b2 commit cde4f43
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 24 deletions.
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 @@ -1215,6 +1215,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>,
is_throw_on_field_error: 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,
is_throw_on_field_error,
);
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 @@ -2258,20 +2290,19 @@ pub(crate) fn raw_response_visit_selections(
enclosing_linked_field_concrete_type,
is_throw_on_field_error,
),
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,
is_throw_on_field_error,
));
}
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,
is_throw_on_field_error,
),
}
}
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?: ?{|
+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.

0 comments on commit cde4f43

Please sign in to comment.