Skip to content

Commit 38ae469

Browse files
tobias-tenglerfacebook-github-bot
authored andcommitted
Fix conditional sub-selections in raw response type (#4774)
Summary: Pull Request resolved: #4774 Test Plan: Ran on WWW and xplat. Found it introduced one Flow issue, which is fixed in D68453153. WIth that change, both xplat and WWW typecheck with the newly generated artifacts. Reviewed By: itamark, lynnshaoyu Differential Revision: D61551118 Pulled By: captbaritone fbshipit-source-id: 4889dd667da90397254f76a91a55d931002771b7
1 parent 6cdea45 commit 38ae469

File tree

5 files changed

+55
-24
lines changed

5 files changed

+55
-24
lines changed

compiler/crates/relay-typegen/src/visit.rs

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,38 @@ fn visit_scalar_field(
12951295
}));
12961296
}
12971297

1298+
#[allow(clippy::too_many_arguments)]
1299+
fn raw_response_visit_condition(
1300+
typegen_context: &'_ TypegenContext<'_>,
1301+
type_selections: &mut Vec<TypeSelection>,
1302+
condition: &Condition,
1303+
encountered_enums: &mut EncounteredEnums,
1304+
match_fields: &mut MatchFields,
1305+
encountered_fragments: &mut EncounteredFragments,
1306+
imported_raw_response_types: &mut ImportedRawResponseTypes,
1307+
runtime_imports: &mut RuntimeImports,
1308+
custom_scalars: &mut CustomScalarsImports,
1309+
enclosing_linked_field_concrete_type: Option<Type>,
1310+
is_throw_on_field_error: bool,
1311+
) {
1312+
let mut selections = raw_response_visit_selections(
1313+
typegen_context,
1314+
&condition.selections,
1315+
encountered_enums,
1316+
match_fields,
1317+
encountered_fragments,
1318+
imported_raw_response_types,
1319+
runtime_imports,
1320+
custom_scalars,
1321+
enclosing_linked_field_concrete_type,
1322+
is_throw_on_field_error,
1323+
);
1324+
for selection in selections.iter_mut() {
1325+
selection.set_conditional(true);
1326+
}
1327+
type_selections.append(&mut selections);
1328+
}
1329+
12981330
#[allow(clippy::too_many_arguments)]
12991331
fn visit_condition(
13001332
typegen_context: &'_ TypegenContext<'_>,
@@ -2338,20 +2370,19 @@ pub(crate) fn raw_response_visit_selections(
23382370
enclosing_linked_field_concrete_type,
23392371
emit_semantic_types,
23402372
),
2341-
Selection::Condition(condition) => {
2342-
type_selections.extend(raw_response_visit_selections(
2343-
typegen_context,
2344-
&condition.selections,
2345-
encountered_enums,
2346-
match_fields,
2347-
encountered_fragments,
2348-
imported_raw_response_types,
2349-
runtime_imports,
2350-
custom_scalars,
2351-
enclosing_linked_field_concrete_type,
2352-
emit_semantic_types,
2353-
));
2354-
}
2373+
Selection::Condition(condition) => raw_response_visit_condition(
2374+
typegen_context,
2375+
&mut type_selections,
2376+
condition,
2377+
encountered_enums,
2378+
match_fields,
2379+
encountered_fragments,
2380+
imported_raw_response_types,
2381+
runtime_imports,
2382+
custom_scalars,
2383+
enclosing_linked_field_concrete_type,
2384+
emit_semantic_types,
2385+
),
23552386
}
23562387
}
23572388
type_selections

compiler/crates/relay-typegen/tests/generate_flow/fixtures/query-with-raw-response-on-conditional.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export type ExampleQuery$data = {|
2929
export type ExampleQuery$rawResponse = {|
3030
+node: ?({|
3131
+__typename: "User",
32-
+feedback: ?{|
32+
+feedback?: ?{|
3333
+id: string,
3434
+name: ?string,
3535
|},
3636
+id: string,
37-
+lastName: ?string,
38-
+name: ?string,
37+
+lastName?: ?string,
38+
+name?: ?string,
3939
|} | {|
4040
+__typename: string,
4141
+id: string,

compiler/crates/relay-typegen/tests/generate_typescript/fixtures/query-with-raw-response-on-conditional.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ export type ExampleQuery$data = {
2929
export type ExampleQuery$rawResponse = {
3030
readonly node: {
3131
readonly __typename: "User";
32-
readonly feedback: {
32+
readonly feedback?: {
3333
readonly id: string;
3434
readonly name: string | null | undefined;
3535
} | null | undefined;
3636
readonly id: string;
37-
readonly lastName: string | null | undefined;
38-
readonly name: string | null | undefined;
37+
readonly lastName?: string | null | undefined;
38+
readonly name?: string | null | undefined;
3939
} | {
4040
readonly __typename: string;
4141
readonly id: string;

packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest_fragment59$normalization.graphql.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/relay-test-utils/__tests__/__generated__/RelayMockPayloadGeneratorTest_fragment61$normalization.graphql.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)