Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 8fbc0b9

Browse filesBrowse files
captbaritonefacebook-github-bot
authored andcommitted
Deprecate returning non-model weak types from resolvers (#5004)
Summary: We implemented this behavior has a shortcut before we had model resolvers. While it may still prove useful in the future, currently it operates as a footgun. It currently works by expecting a fully deeply populated network shaped response for the object and _all_ of its possible children (deeply nested) and then normalizes and publishes that data into the store at read time. This creates a complex write-during-read cycle which is difficult to reason about and has confusing perf characteristics. Pull Request resolved: #5004 Test Plan: Runs on both www and xplat without triggering any errors Reviewed By: tyao1 Differential Revision: D75182848 Pulled By: captbaritone fbshipit-source-id: 8bbb21586f31b02bf663d74ad019d5b4e07b53c2
1 parent f3d0bed commit 8fbc0b9
Copy full SHA for 8fbc0b9

17 files changed

+200-21Lines changed: 200 additions & 21 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎compiler/crates/common/src/feature_flags.rs‎

Copy file name to clipboardExpand all lines: compiler/crates/common/src/feature_flags.rs
+14-2Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,21 @@ use crate::rollout::RolloutRange;
2323
#[serde(deny_unknown_fields)]
2424
pub struct FeatureFlags {
2525
#[serde(default)]
26-
// Enable returning interfaces from Relay Resolvers without @outputType
26+
/// Enable returning interfaces from Relay Resolvers without @outputType
2727
pub relay_resolver_enable_interface_output_type: FeatureFlag,
2828

29+
#[serde(default)]
30+
/// @outputType resolvers are a discontinued experimental feature. This flag
31+
/// allows users to allowlist old uses of this feature while they work to
32+
/// remove them. Weak types (types without an `id` field) returned by a Relay
33+
/// Resolver should be limited to types defined using `@RelayResolver` with `@weak`.
34+
///
35+
/// If using the "limited" feature flag variant, users can allowlist a
36+
/// specific list of field names.
37+
///
38+
/// https://relay.dev/docs/next/guides/relay-resolvers/defining-types/#defining-a-weak-type
39+
pub allow_output_type_resolvers: FeatureFlag,
40+
2941
/// For now, this also disallows fragments with variable definitions
3042
/// This also makes @module to opt in using @no_inline internally
3143
/// NOTE that the presence of a fragment in this list only controls whether a fragment is *allowed* to
@@ -169,7 +181,7 @@ pub struct FeatureFlags {
169181
pub legacy_include_path_in_required_reader_nodes: FeatureFlag,
170182
}
171183

172-
#[derive(Debug, Deserialize, Clone, Serialize, Default, JsonSchema)]
184+
#[derive(Debug, serde::Deserialize, Clone, Serialize, Default, JsonSchema)]
173185
#[serde(tag = "kind", rename_all = "lowercase")]
174186
pub enum FeatureFlag {
175187
/// Fully disabled: developers may not use this feature
Collapse file

‎compiler/crates/relay-compiler/relay-compiler-config-schema.json‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/relay-compiler-config-schema.json
+15Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,17 @@
633633
}
634634
]
635635
},
636+
"allow_output_type_resolvers": {
637+
"description": "@outputType resolvers are a discontinued experimental feature. This flag allows users to allowlist old uses of this feature while they work to remove them. Weak types (types without an `id` field) returned by a Relay Resolver should be limited to types defined using `@RelayResolver` with `@weak`.\n\nIf using the \"limited\" feature flag variant, users can allowlist a specific list of field names.\n\nhttps://relay.dev/docs/next/guides/relay-resolvers/defining-types/#defining-a-weak-type",
638+
"default": {
639+
"kind": "disabled"
640+
},
641+
"allOf": [
642+
{
643+
"$ref": "#/definitions/FeatureFlag"
644+
}
645+
]
646+
},
636647
"allow_required_in_mutation_response": {
637648
"description": "@required with an action of THROW is read-time feature that is not compatible with our mutation APIs. We are in the process of removing any existing examples, but this flag is part of a process of removing any existing examples.",
638649
"default": {
@@ -799,6 +810,7 @@
799810
"type": "boolean"
800811
},
801812
"relay_resolver_enable_interface_output_type": {
813+
"description": "Enable returning interfaces from Relay Resolvers without @outputType",
802814
"default": {
803815
"kind": "disabled"
804816
},
@@ -1016,6 +1028,9 @@
10161028
"actor_change_support": {
10171029
"kind": "disabled"
10181030
},
1031+
"allow_output_type_resolvers": {
1032+
"kind": "disabled"
1033+
},
10191034
"allow_required_in_mutation_response": {
10201035
"kind": "disabled"
10211036
},
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.expected‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.expected
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ graphql`mutation barMutation {
1818
"language": "flow",
1919
"schema": "./schema.graphql",
2020
"featureFlags": {
21-
"enable_relay_resolver_mutations": true
21+
"enable_relay_resolver_mutations": true,
22+
"allow_output_type_resolvers": {
23+
"kind": "enabled"
24+
}
2225
},
2326
"schemaExtensions": [
2427
"./extensions.graphql"
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.input‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_different_mutation_ok.input
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ graphql`mutation barMutation {
1717
"language": "flow",
1818
"schema": "./schema.graphql",
1919
"featureFlags": {
20-
"enable_relay_resolver_mutations": true
20+
"enable_relay_resolver_mutations": true,
21+
"allow_output_type_resolvers": {
22+
"kind": "enabled"
23+
}
2124
},
2225
"schemaExtensions": [
2326
"./extensions.graphql"
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.expected‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.expected
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ graphql`mutation barMutation {
1212
//- relay.config.json
1313
{
1414
"language": "flow",
15-
"schema": "./schema.graphql"
15+
"schema": "./schema.graphql",
16+
"featureFlags": {
17+
"allow_output_type_resolvers": {
18+
"kind": "enabled"
19+
}
20+
}
1621
}
1722

1823
//- schema.graphql
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.input‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_disabled.input
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ graphql`mutation barMutation {
1111
//- relay.config.json
1212
{
1313
"language": "flow",
14-
"schema": "./schema.graphql"
14+
"schema": "./schema.graphql",
15+
"featureFlags": {
16+
"allow_output_type_resolvers": {
17+
"kind": "enabled"
18+
}
19+
}
1520
}
1621

1722
//- schema.graphql
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_nonscalar.expected‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_nonscalar.expected
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,10 @@ graphql`mutation barMutation {
3030
"language": "flow",
3131
"schema": "./schema.graphql",
3232
"featureFlags": {
33-
"enable_relay_resolver_mutations": true
33+
"enable_relay_resolver_mutations": true,
34+
"allow_output_type_resolvers": {
35+
"kind": "enabled"
36+
}
3437
},
3538
"schemaExtensions": [
3639
"./extensions.graphql"
Collapse file

‎compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_nonscalar.input‎

Copy file name to clipboardExpand all lines: compiler/crates/relay-compiler/tests/relay_compiler_integration/fixtures/client_mutation_resolver_invalid_nonscalar.input
+4-1Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,10 @@ graphql`mutation barMutation {
2929
"language": "flow",
3030
"schema": "./schema.graphql",
3131
"featureFlags": {
32-
"enable_relay_resolver_mutations": true
32+
"enable_relay_resolver_mutations": true,
33+
"allow_output_type_resolvers": {
34+
"kind": "enabled"
35+
}
3336
},
3437
"schemaExtensions": [
3538
"./extensions.graphql"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
==================================== INPUT ====================================
2+
//- PersonComponent.js
3+
graphql`query PersonComponentQuery {
4+
some_resolver_field {
5+
__typename
6+
}
7+
}`
8+
9+
//- Resolvers.js
10+
/**
11+
* @RelayResolver Query.some_resolver_field: SomeType
12+
*/
13+
14+
//- relay.config.json
15+
{
16+
"language": "typescript",
17+
"schema": "schema.graphql",
18+
"schemaExtensions": [
19+
"schema-extensions"
20+
]
21+
}
22+
23+
//- schema.graphql
24+
type Query {
25+
some_field: Boolean
26+
}
27+
28+
//- schema-extensions/extension.graphql
29+
type SomeType {
30+
name: String
31+
}
32+
==================================== OUTPUT ===================================
33+
✖︎ Relay Resolvers that return weak types defined in client schema extensions are not supported. Prefer defining the return type using a `@weak` Relay Resolver type: https://relay.dev/docs/next/guides/relay-resolvers/defining-types/#defining-a-weak-type
34+
35+
Resolvers.js:2:25
36+
1 │ *
37+
2 │ * @RelayResolver Query.some_resolver_field: SomeType
38+
│ ^^^^^^^^^^^^^^^^^^^
39+
3 │
Collapse file
+30Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//- PersonComponent.js
2+
graphql`query PersonComponentQuery {
3+
some_resolver_field {
4+
__typename
5+
}
6+
}`
7+
8+
//- Resolvers.js
9+
/**
10+
* @RelayResolver Query.some_resolver_field: SomeType
11+
*/
12+
13+
//- relay.config.json
14+
{
15+
"language": "typescript",
16+
"schema": "schema.graphql",
17+
"schemaExtensions": [
18+
"schema-extensions"
19+
]
20+
}
21+
22+
//- schema.graphql
23+
type Query {
24+
some_field: Boolean
25+
}
26+
27+
//- schema-extensions/extension.graphql
28+
type SomeType {
29+
name: String
30+
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.