Skip to content

Commit 71b6560

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Disable @weak interface implementation validate if feature flag enabled
Reviewed By: tyao1 Differential Revision: D53070318 fbshipit-source-id: 7765dcfeedcbba5e79bc452633e7d13c0189c216
1 parent 8e557f9 commit 71b6560

File tree

11 files changed

+97
-16
lines changed

11 files changed

+97
-16
lines changed

compiler/crates/relay-compiler/src/docblocks.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,9 @@ fn parse_source(
8585
allow_legacy_verbose_syntax: &project_config
8686
.feature_flags
8787
.relay_resolvers_allow_legacy_verbose_syntax,
88+
enable_interface_output_type: &project_config
89+
.feature_flags
90+
.relay_resolver_enable_interface_output_type,
8891
},
8992
)?;
9093
maybe_ir

compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/resolver_returns_interface_of_all_weak_model_type.expected

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -56,18 +56,9 @@ interface IPerson {
5656
name: String
5757
}
5858
==================================== OUTPUT ===================================
59-
✖︎ The compiler attempted to parse "Admin implements IPerson" as a GraphQL type (e.g. `Viewer` or `User`), but had unparsed characters remaining. Try removing everything after "Admin".
59+
✖︎ No types implement the client interface IPerson. Interfaces returned by a @RelayResolver must have at least one concrete implementation.
6060

61-
AdminTypeResolvers.js:2:19
62-
1 │ *
63-
2 │ * @RelayResolver Admin implements IPerson
64-
│ ^^^^^^^^^^^^^^^^^^^^^^^^
65-
3 │ * @weak
66-
67-
✖︎ The compiler attempted to parse "User implements IPerson" as a GraphQL type (e.g. `Viewer` or `User`), but had unparsed characters remaining. Try removing everything after "User".
68-
69-
UserTypeResolvers.js:2:19
70-
1 │ *
71-
2 │ * @RelayResolver User implements IPerson
72-
│ ^^^^^^^^^^^^^^^^^^^^^^^
73-
3 │ * @weak
61+
schema-extensions/extension.graphql:1:11
62+
1 │ interface IPerson {
63+
│ ^^^^^^^
64+
2 │ name: String

compiler/crates/relay-docblock/src/docblock_ir.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ pub(crate) fn parse_docblock_ir(
159159
populated_ir_field,
160160
weak_field,
161161
source_hash,
162+
parse_options,
162163
)?),
163164
None => DocblockIr::StrongObjectResolver(parse_strong_object_ir(
164165
project_name,
@@ -300,9 +301,17 @@ fn parse_weak_object_ir(
300301
relay_resolver_field: PopulatedIrField,
301302
_weak_field: UnpopulatedIrField,
302303
source_hash: ResolverSourceHash,
304+
parse_options: &ParseOptions<'_>,
303305
) -> DiagnosticsResult<WeakObjectIr> {
304306
// Validate that the right hand side of the @RelayResolver field is a valid identifier
305-
let identifier = assert_only_identifier(relay_resolver_field)?;
307+
let identifier = if parse_options
308+
.enable_interface_output_type
309+
.is_fully_enabled()
310+
{
311+
extract_identifier(relay_resolver_field)?
312+
} else {
313+
assert_only_identifier(relay_resolver_field)?
314+
};
306315

307316
Ok(WeakObjectIr {
308317
type_name: identifier,

compiler/crates/relay-docblock/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ pub struct ParseOptions<'a> {
4141
pub enable_output_type: &'a FeatureFlag,
4242
pub enable_strict_resolver_flavors: &'a FeatureFlag,
4343
pub allow_legacy_verbose_syntax: &'a FeatureFlag,
44+
pub enable_interface_output_type: &'a FeatureFlag,
4445
}
4546

4647
pub fn parse_docblock_ast(
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
==================================== INPUT ====================================
2+
/**
3+
* Copyright (c) Meta Platforms, Inc. and affiliates.
4+
*
5+
* This source code is licensed under the MIT license found in the
6+
* LICENSE file in the root directory of this source tree.
7+
*/
8+
9+
// relay:enable_interface_output_type
10+
11+
/**
12+
* @RelayResolver ClientUser implements Foo
13+
* @weak
14+
*/
15+
==================================== OUTPUT ===================================
16+
WeakObjectType(
17+
WeakObjectIr {
18+
type_name: Identifier {
19+
span: 20:30,
20+
token: Token {
21+
span: 20:30,
22+
kind: Identifier,
23+
},
24+
value: "ClientUser",
25+
},
26+
rhs_location: /path/to/test/fixture/relay-resolver-weak-object-with-implements.js:20:45,
27+
description: None,
28+
hack_source: None,
29+
deprecated: None,
30+
location: /path/to/test/fixture/relay-resolver-weak-object-with-implements.js:0:55,
31+
source_hash: ResolverSourceHash(
32+
"26ae5e285958dda3877b78aaf5a82b65",
33+
),
34+
},
35+
)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Meta Platforms, Inc. and affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
// relay:enable_interface_output_type
9+
10+
/**
11+
* @RelayResolver ClientUser implements Foo
12+
* @weak
13+
*/

compiler/crates/relay-docblock/tests/parse/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,14 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
8787
} else {
8888
&FeatureFlag::Disabled
8989
},
90+
enable_interface_output_type: if fixture
91+
.content
92+
.contains("// relay:enable_interface_output_type")
93+
{
94+
&FeatureFlag::Enabled
95+
} else {
96+
&FeatureFlag::Disabled
97+
},
9098
},
9199
)
92100
})

compiler/crates/relay-docblock/tests/parse_test.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<c9768c7dbf870b21e26aa508af34c942>>
7+
* @generated SignedSource<<0d097e7d292511eaacec9df447a793d7>>
88
*/
99

1010
mod parse;
@@ -194,6 +194,13 @@ async fn relay_resolver_weak_object_with_gibberish_invalid() {
194194
test_fixture(transform_fixture, file!(), "relay-resolver-weak-object-with-gibberish.invalid.js", "parse/fixtures/relay-resolver-weak-object-with-gibberish.invalid.expected", input, expected).await;
195195
}
196196

197+
#[tokio::test]
198+
async fn relay_resolver_weak_object_with_implements() {
199+
let input = include_str!("parse/fixtures/relay-resolver-weak-object-with-implements.js");
200+
let expected = include_str!("parse/fixtures/relay-resolver-weak-object-with-implements.expected");
201+
test_fixture(transform_fixture, file!(), "relay-resolver-weak-object-with-implements.js", "parse/fixtures/relay-resolver-weak-object-with-implements.expected", input, expected).await;
202+
}
203+
197204
#[tokio::test]
198205
async fn relay_resolver_with_args() {
199206
let input = include_str!("parse/fixtures/relay-resolver-with-args.js");

compiler/crates/relay-docblock/tests/to_schema/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,14 @@ pub async fn transform_fixture(fixture: &Fixture<'_>) -> Result<String, String>
8989
} else {
9090
&FeatureFlag::Disabled
9191
},
92+
enable_interface_output_type: if fixture
93+
.content
94+
.contains("// relay:enable_interface_output_type")
95+
{
96+
&FeatureFlag::Enabled
97+
} else {
98+
&FeatureFlag::Disabled
99+
},
92100
},
93101
)?
94102
.unwrap();

compiler/crates/relay-lsp/src/server/lsp_state.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,9 @@ impl<TPerfLogger: PerfLogger + 'static, TSchemaDocumentation: SchemaDocumentatio
306306
allow_legacy_verbose_syntax: &project_config
307307
.feature_flags
308308
.relay_resolvers_allow_legacy_verbose_syntax,
309+
enable_interface_output_type: &project_config
310+
.feature_flags
311+
.relay_resolver_enable_interface_output_type,
309312
},
310313
)
311314
});

0 commit comments

Comments
 (0)