diff --git a/compiler/crates/docblock-shared/src/lib.rs b/compiler/crates/docblock-shared/src/lib.rs index 6a7a6e5112fb6..0efc096dc143d 100644 --- a/compiler/crates/docblock-shared/src/lib.rs +++ b/compiler/crates/docblock-shared/src/lib.rs @@ -42,6 +42,9 @@ lazy_static! { pub static ref EDGE_TO_FIELD: StringKey = "edgeTo".intern(); pub static ref DEPRECATED_FIELD: StringKey = "deprecated".intern(); pub static ref LIVE_FIELD: StringKey = "live".intern(); + // Using a longer name version for this "special" field + // help us avoid potential collision with product code (__self, __instance can be used for something else) + pub static ref RELAY_RESOLVER_MODEL_INSTANCE_FIELD: StringKey = "__relay_model_instance".intern(); pub static ref ROOT_FRAGMENT_FIELD: StringKey = "rootFragment".intern(); pub static ref OUTPUT_TYPE_FIELD: StringKey = "outputType".intern(); pub static ref WEAK_FIELD: StringKey = "weak".intern(); diff --git a/compiler/crates/relay-docblock/src/ir.rs b/compiler/crates/relay-docblock/src/ir.rs index 6c7c5a6a21523..cadb9f779aec8 100644 --- a/compiler/crates/relay-docblock/src/ir.rs +++ b/compiler/crates/relay-docblock/src/ir.rs @@ -30,6 +30,7 @@ use docblock_shared::KEY_RESOLVER_ID_FIELD; use docblock_shared::LIVE_ARGUMENT_NAME; use docblock_shared::RELAY_RESOLVER_DIRECTIVE_NAME; use docblock_shared::RELAY_RESOLVER_MODEL_DIRECTIVE_NAME; +use docblock_shared::RELAY_RESOLVER_MODEL_INSTANCE_FIELD; use docblock_shared::RELAY_RESOLVER_SOURCE_HASH; use docblock_shared::RELAY_RESOLVER_SOURCE_HASH_VALUE; use docblock_shared::RELAY_RESOLVER_WEAK_OBJECT_DIRECTIVE; @@ -84,7 +85,6 @@ lazy_static! { static ref DEPRECATED_RESOLVER_DIRECTIVE_NAME: DirectiveName = DirectiveName("deprecated".intern()); static ref DEPRECATED_REASON_ARGUMENT_NAME: ArgumentName = ArgumentName("reason".intern()); - static ref RESOLVER_MODEL_INSTANCE_FIELD_NAME: StringKey = "__relay_model_instance".intern(); static ref MODEL_CUSTOM_SCALAR_TYPE_SUFFIX: StringKey = "Model".intern(); } @@ -1518,13 +1518,13 @@ fn get_root_fragment_for_object( project_name .generate_name_for_object_and_field( object.unwrap().name.item.0, - *RESOLVER_MODEL_INSTANCE_FIELD_NAME, + *RELAY_RESOLVER_MODEL_INSTANCE_FIELD, ) .intern(), )), generated: true, inject_fragment_data: Some(FragmentDataInjectionMode::Field( - *RESOLVER_MODEL_INSTANCE_FIELD_NAME, + *RELAY_RESOLVER_MODEL_INSTANCE_FIELD, )), }) } else { @@ -1556,7 +1556,7 @@ fn generate_model_instance_field( }); FieldDefinition { - name: string_key_as_identifier(*RESOLVER_MODEL_INSTANCE_FIELD_NAME), + name: string_key_as_identifier(*RELAY_RESOLVER_MODEL_INSTANCE_FIELD), type_: TypeAnnotation::NonNull(Box::new(NonNullTypeAnnotation { span, type_: TypeAnnotation::Named(NamedTypeAnnotation { diff --git a/compiler/crates/relay-transforms/src/generate_relay_resolvers_model_fragments.rs b/compiler/crates/relay-transforms/src/generate_relay_resolvers_model_fragments.rs index 702d24b9bb67b..0790fc3c63b88 100644 --- a/compiler/crates/relay-transforms/src/generate_relay_resolvers_model_fragments.rs +++ b/compiler/crates/relay-transforms/src/generate_relay_resolvers_model_fragments.rs @@ -11,6 +11,7 @@ use common::NamedItem; use common::WithLocation; use docblock_shared::ResolverSourceHash; use docblock_shared::RELAY_RESOLVER_MODEL_DIRECTIVE_NAME; +use docblock_shared::RELAY_RESOLVER_MODEL_INSTANCE_FIELD; use docblock_shared::RELAY_RESOLVER_SOURCE_HASH; use docblock_shared::RELAY_RESOLVER_SOURCE_HASH_VALUE; use graphql_ir::associated_data_impl; @@ -21,19 +22,10 @@ use graphql_ir::Program; use graphql_ir::ScalarField; use graphql_ir::Selection; use intern::string_key::Intern; -use intern::string_key::StringKey; -use lazy_static::lazy_static; use relay_config::ProjectName; use relay_config::SchemaConfig; use schema::Schema; -lazy_static! { - // Using a longer name version for this "special" field - // help us avoid potential collision with product code (__self, __instance can be used for something else) - static ref RESOLVER_MODEL_INSTANCE_FIELD_NAME: StringKey = - "__relay_model_instance".intern(); -} - /// Currently, this is a wrapper of the hash of the resolver source code. /// But we can change this `ArtifactSourceKeyData` to be an /// enum and also represent the `fragment` or `operation` names. @@ -61,11 +53,11 @@ pub fn generate_relay_resolvers_model_fragments( let object_type = program.schema.get_type(object.name.item.0).unwrap(); let model_instance_field_id = program .schema - .named_field(object_type, *RESOLVER_MODEL_INSTANCE_FIELD_NAME) + .named_field(object_type, *RELAY_RESOLVER_MODEL_INSTANCE_FIELD) .unwrap_or_else(|| { panic!( "Objects with directive @{} expected to have field `{}`.", - *RELAY_RESOLVER_MODEL_DIRECTIVE_NAME, *RESOLVER_MODEL_INSTANCE_FIELD_NAME + *RELAY_RESOLVER_MODEL_DIRECTIVE_NAME, *RELAY_RESOLVER_MODEL_INSTANCE_FIELD ) }); @@ -73,7 +65,7 @@ pub fn generate_relay_resolvers_model_fragments( project_name .generate_name_for_object_and_field( object.name.item.0, - *RESOLVER_MODEL_INSTANCE_FIELD_NAME, + *RELAY_RESOLVER_MODEL_INSTANCE_FIELD, ) .intern(), );