Skip to content

Commit 52f5f81

Browse files
captbaritonefacebook-github-bot
authored andcommitted
Mark generate resolver model id fields with metadata directive
Reviewed By: gordyf Differential Revision: D67815204 fbshipit-source-id: d8b88f385a4a958047748fc81102877e58297263
1 parent 74396d7 commit 52f5f81

31 files changed

+42
-31
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ lazy_static! {
3838
/// a Relay Resolver model.
3939
pub static ref RELAY_RESOLVER_MODEL_DIRECTIVE_NAME: DirectiveName =
4040
DirectiveName("__RelayResolverModel".intern());
41+
/// A field directive which indicates that the field is the generated ID field for a model type.
42+
pub static ref RELAY_RESOLVER_MODEL_GENERATED_ID_FIELD_DIRECTIVE_NAME: DirectiveName =
43+
DirectiveName("__RelayResolverModelGeneratedIDField".intern());
4144
/// If a field or model type has a @relay_resolver directive (see above)
4245
/// this argument name is used to track its @rootFragment (if any).
4346
pub static ref FRAGMENT_KEY_ARGUMENT_NAME: ArgumentName =

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ use docblock_shared::INJECT_FRAGMENT_DATA_ARGUMENT_NAME;
2828
use docblock_shared::LIVE_ARGUMENT_NAME;
2929
use docblock_shared::RELAY_RESOLVER_DIRECTIVE_NAME;
3030
use docblock_shared::RELAY_RESOLVER_MODEL_DIRECTIVE_NAME;
31+
use docblock_shared::RELAY_RESOLVER_MODEL_GENERATED_ID_FIELD_DIRECTIVE_NAME;
3132
use docblock_shared::RELAY_RESOLVER_MODEL_INSTANCE_FIELD;
3233
use docblock_shared::RELAY_RESOLVER_SOURCE_HASH;
3334
use docblock_shared::RELAY_RESOLVER_SOURCE_HASH_VALUE;
@@ -1193,7 +1194,14 @@ impl StrongObjectIr {
11931194
exclamation: dummy_token(span),
11941195
})),
11951196
arguments: None,
1196-
directives: vec![],
1197+
directives: vec![ConstantDirective {
1198+
span,
1199+
at: dummy_token(span),
1200+
name: string_key_as_identifier(
1201+
RELAY_RESOLVER_MODEL_GENERATED_ID_FIELD_DIRECTIVE_NAME.0,
1202+
),
1203+
arguments: None,
1204+
}],
11971205
description: None,
11981206
hack_source: None,
11991207
span,

compiler/crates/relay-docblock/tests/to_schema/fixtures/legacy-relay-resolver-with-root-fragment-on-model.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ graphql`
2626
`
2727
==================================== OUTPUT ===================================
2828
type MyType @__RelayResolverModel {
29-
id: ID!
29+
id: ID! @__RelayResolverModelGeneratedIDField
3030
__relay_model_instance: RelayResolverValue! @relay_resolver(fragment_name: "MyType__id", generated_fragment: true, inject_fragment_data: "id", import_name: "MyType", import_path: "/path/to/test/fixture/legacy-relay-resolver-with-root-fragment-on-model.js") @resolver_source_hash(value: "b81f253a757aaba36955be6d8e224c2a") @unselectable(reason: "This field is intended only for Relay's internal use")
3131
}
3232

compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-strong-object-with-implements.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ interface IFoo {
2020
`
2121
==================================== OUTPUT ===================================
2222
type ClientUser implements IFoo @__RelayResolverModel {
23-
id: ID!
23+
id: ID! @__RelayResolverModelGeneratedIDField
2424
__relay_model_instance: RelayResolverValue! @relay_resolver(fragment_name: "ClientUser__id", generated_fragment: true, inject_fragment_data: "id", import_name: "ClientUser", import_path: "/path/to/test/fixture/relay-resolver-strong-object-with-implements.js") @resolver_source_hash(value: "76be3b85f11135352a0d3a5726418956") @unselectable(reason: "This field is intended only for Relay's internal use")
2525
}

compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-strong-object-with-multiple-implements.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@ interface IBar {
2626
`
2727
==================================== OUTPUT ===================================
2828
type ClientUser implements IFoo & IBar @__RelayResolverModel {
29-
id: ID!
29+
id: ID! @__RelayResolverModelGeneratedIDField
3030
__relay_model_instance: RelayResolverValue! @relay_resolver(fragment_name: "ClientUser__id", generated_fragment: true, inject_fragment_data: "id", import_name: "ClientUser", import_path: "/path/to/test/fixture/relay-resolver-strong-object-with-multiple-implements.js") @resolver_source_hash(value: "1b7346b6155a43514be2946721ff59fb") @unselectable(reason: "This field is intended only for Relay's internal use")
3131
}

compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-strong-object.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@
1111
*/
1212
==================================== OUTPUT ===================================
1313
type ClientUser @__RelayResolverModel {
14-
id: ID!
14+
id: ID! @__RelayResolverModelGeneratedIDField
1515
__relay_model_instance: RelayResolverValue! @relay_resolver(fragment_name: "ClientUser__id", generated_fragment: true, inject_fragment_data: "id", import_name: "ClientUser", import_path: "/path/to/test/fixture/relay-resolver-strong-object.js") @resolver_source_hash(value: "b1c8ae1937aed7425f5a87a4762ad83d") @unselectable(reason: "This field is intended only for Relay's internal use")
1616
}

compiler/crates/relay-docblock/tests/to_schema/fixtures/terse-relay-resolver-with-root-fragment-on-model.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ graphql`
2222
`
2323
==================================== OUTPUT ===================================
2424
type MyType @__RelayResolverModel {
25-
id: ID!
25+
id: ID! @__RelayResolverModelGeneratedIDField
2626
__relay_model_instance: RelayResolverValue! @relay_resolver(fragment_name: "MyType__id", generated_fragment: true, inject_fragment_data: "id", import_name: "MyType", import_path: "/path/to/test/fixture/terse-relay-resolver-with-root-fragment-on-model.js") @resolver_source_hash(value: "b81f253a757aaba36955be6d8e224c2a") @unselectable(reason: "This field is intended only for Relay's internal use")
2727
}
2828

compiler/crates/relay-schema-generation/tests/docblock/fixtures/arguments.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ Type(
278278
),
279279
)
280280
type Cat @__RelayResolverModel {
281-
id: ID!
281+
id: ID! @__RelayResolverModelGeneratedIDField
282282
__relay_model_instance: RelayResolverValue! @relay_resolver(generated_fragment: true, fragment_name: "Cat__id", import_name: "Cat", import_path: "module.js", inject_fragment_data: "id") @resolver_source_hash(value: "9eb0075d1ca5f38ce3ae8a364b4fb1be") @unselectable(reason: "This field is intended only for Relay's internal use")
283283
}
284284

compiler/crates/relay-schema-generation/tests/docblock/fixtures/built-in-scalar-id.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,6 @@ Type(
127127
),
128128
)
129129
type Cat @__RelayResolverModel {
130-
id: ID!
130+
id: ID! @__RelayResolverModelGeneratedIDField
131131
__relay_model_instance: RelayResolverValue! @relay_resolver(generated_fragment: true, fragment_name: "Cat__id", import_name: "Cat", import_path: "Cat.js", inject_fragment_data: "id") @resolver_source_hash(value: "a9744194670e59356ad37913eff9defe") @unselectable(reason: "This field is intended only for Relay's internal use")
132132
}

compiler/crates/relay-schema-generation/tests/docblock/fixtures/conflicting-type-definitions.error.expected

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Type(
8181
),
8282
)
8383
type Cat @__RelayResolverModel {
84-
id: ID!
84+
id: ID! @__RelayResolverModelGeneratedIDField
8585
__relay_model_instance: RelayResolverValue! @relay_resolver(generated_fragment: true, fragment_name: "Cat__id", import_name: "Cat", import_path: "Cat.js", inject_fragment_data: "id") @resolver_source_hash(value: "1b432d1f1ef72adb427857abb24a5068") @unselectable(reason: "This field is intended only for Relay's internal use")
8686
}
8787

0 commit comments

Comments
 (0)