diff --git a/compiler/crates/relay-codegen/src/build_ast.rs b/compiler/crates/relay-codegen/src/build_ast.rs index 295f655fd319f..ace397d5b35e4 100644 --- a/compiler/crates/relay-codegen/src/build_ast.rs +++ b/compiler/crates/relay-codegen/src/build_ast.rs @@ -1003,7 +1003,7 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { // information to _read_ the resolver. Specifically, enough data // to construct a fragment key, and an import of the resolver // module itself. - Primitive::Key(self.object(object! { + let mut object_props = object! { :build_alias(field_alias, field_name), args: match args { None => Primitive::SkippableNull, @@ -1017,7 +1017,36 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { name: Primitive::String(field_name), resolver_module: Primitive::JSModuleDependency(import_path), path: Primitive::String(path), - })) + }; + + if let Some(normalization_info) = &relay_resolver_metadata.normalization_info { + let normalization_artifact_source_location = normalization_info + .normalization_operation + .location + .source_location(); + + let path_for_artifact = self.project_config.create_path_for_artifact( + normalization_artifact_source_location, + normalization_info.normalization_operation.item.to_string(), + ); + + let normalization_import_path = self.project_config.js_module_import_path( + self.definition_source_location, + path_for_artifact.to_str().unwrap().intern(), + ); + let normalization_info = object! { + concrete_type: Primitive::String(normalization_info.type_name), + plural: Primitive::Bool(normalization_info.plural), + normalization_node: Primitive::GraphQLModuleDependency(normalization_import_path), + }; + + object_props.push(ObjectEntry { + key: CODEGEN_CONSTANTS.relay_resolver_normalization_info, + value: Primitive::Key(self.object(normalization_info)), + }) + } + + Primitive::Key(self.object(object_props)) } fn build_normalization_fragment_spread( @@ -1237,37 +1266,13 @@ impl<'schema, 'builder, 'config> CodegenBuilder<'schema, 'builder, 'config> { client_edge_selections_key: selections_item, })) } - ClientEdgeMetadataDirective::ClientObject { - type_name, - normalization_operation, - .. - } => { - let mut object_props = object! { + ClientEdgeMetadataDirective::ClientObject { type_name, .. } => { + Primitive::Key(self.object(object! { kind: Primitive::String(CODEGEN_CONSTANTS.client_edge_to_client_object), concrete_type: Primitive::String(type_name), client_edge_backing_field_key: backing_field, client_edge_selections_key: selections_item, - }; - if let Some(normalization_operation) = normalization_operation { - let normalization_artifact_source_location = - normalization_operation.location.source_location(); - - let path_for_artifact = self.project_config.create_path_for_artifact( - normalization_artifact_source_location, - normalization_operation.item.to_string(), - ); - - let normalization_import_path = self.project_config.js_module_import_path( - self.definition_source_location, - path_for_artifact.to_str().unwrap().intern(), - ); - - object_props.push(ObjectEntry { - key: CODEGEN_CONSTANTS.client_edge_normalization_node_key, - value: Primitive::GraphQLModuleDependency(normalization_import_path), - }) - } - Primitive::Key(self.object(object_props)) + })) } }; diff --git a/compiler/crates/relay-codegen/src/constants.rs b/compiler/crates/relay-codegen/src/constants.rs index c54fad623b50e..00cdbd4784f7e 100644 --- a/compiler/crates/relay-codegen/src/constants.rs +++ b/compiler/crates/relay-codegen/src/constants.rs @@ -24,7 +24,6 @@ pub struct CodegenConstants { pub client_component: StringKey, pub client_edge_backing_field_key: StringKey, pub client_edge_selections_key: StringKey, - pub client_edge_normalization_node_key: StringKey, pub client_edge_to_client_object: StringKey, pub client_edge_to_server_object: StringKey, pub client_extension: StringKey, @@ -80,6 +79,7 @@ pub struct CodegenConstants { pub module_import: StringKey, pub mutation: StringKey, pub name: StringKey, + pub normalization_node: StringKey, pub object_value: StringKey, pub operation_kind: StringKey, pub operation_module_provider: StringKey, @@ -95,6 +95,7 @@ pub struct CodegenConstants { pub query: StringKey, pub refetch: StringKey, pub relay_live_resolver: StringKey, + pub relay_resolver_normalization_info: StringKey, pub relay_resolver: StringKey, pub request: StringKey, pub required_field: StringKey, @@ -132,7 +133,6 @@ lazy_static! { client_component: "ClientComponent".intern(), client_edge_backing_field_key: "backingField".intern(), client_edge_selections_key: "linkedField".intern(), - client_edge_normalization_node_key: "normalizationNode".intern(), client_edge_to_client_object: "ClientEdgeToClientObject".intern(), client_edge_to_server_object: "ClientEdgeToServerObject".intern(), client_extension: "ClientExtension".intern(), @@ -188,6 +188,7 @@ lazy_static! { module_import: "ModuleImport".intern(), mutation: "mutation".intern(), name: "name".intern(), + normalization_node: "normalizationNode".intern(), object_value: "ObjectValue".intern(), operation_kind: "operationKind".intern(), operation_module_provider: "operationModuleProvider".intern(), @@ -203,6 +204,7 @@ lazy_static! { query: "query".intern(), refetch: "refetch".intern(), relay_live_resolver: "RelayLiveResolver".intern(), + relay_resolver_normalization_info: "normalizationInfo".intern(), relay_resolver: "RelayResolver".intern(), request: "Request".intern(), required_field: "RequiredField".intern(), diff --git a/compiler/crates/relay-docblock/src/ir.rs b/compiler/crates/relay-docblock/src/ir.rs index 4bfc19bc2899c..9fcede50803a5 100644 --- a/compiler/crates/relay-docblock/src/ir.rs +++ b/compiler/crates/relay-docblock/src/ir.rs @@ -57,7 +57,8 @@ lazy_static! { static ref IMPORT_PATH_ARGUMENT_NAME: ArgumentName = ArgumentName("import_path".intern()); static ref LIVE_ARGUMENT_NAME: ArgumentName = ArgumentName("live".intern()); static ref DEPRECATED_REASON_ARGUMENT_NAME: ArgumentName = ArgumentName("reason".intern()); - static ref IS_OUTPUT_TYPE_ARGUMENT_NAME: ArgumentName = ArgumentName("is_output_type".intern()); + static ref HAS_OUTPUT_TYPE_ARGUMENT_NAME: ArgumentName = + ArgumentName("has_output_type".intern()); } #[derive(Debug, PartialEq)] @@ -447,7 +448,7 @@ impl RelayResolverIr { if let Some(OutputType::Output(type_)) = &self.output_type { arguments.push(true_argument( - IS_OUTPUT_TYPE_ARGUMENT_NAME.0, + HAS_OUTPUT_TYPE_ARGUMENT_NAME.0, type_.location, )) } diff --git a/compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-with-output-type.expected b/compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-with-output-type.expected index 790b6bfe48e08..7a43dd2c29f11 100644 --- a/compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-with-output-type.expected +++ b/compiler/crates/relay-docblock/tests/to_schema/fixtures/relay-resolver-with-output-type.expected @@ -27,5 +27,5 @@ graphql` ` ==================================== OUTPUT =================================== extend type User { - favorite_page: ClientPage @relay_resolver(import_path: "/path/to/test/fixture/relay-resolver-with-output-type.js", fragment_name: "myRootFragment", is_output_type: true) + favorite_page: ClientPage @relay_resolver(import_path: "/path/to/test/fixture/relay-resolver-with-output-type.js", fragment_name: "myRootFragment", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/src/client_edges.rs b/compiler/crates/relay-transforms/src/client_edges.rs index a7247cfa4ba59..4c798ebe6e697 100644 --- a/compiler/crates/relay-transforms/src/client_edges.rs +++ b/compiler/crates/relay-transforms/src/client_edges.rs @@ -40,7 +40,6 @@ use schema::Schema; use schema::Type; use super::ValidationMessageWithData; -use crate::generate_relay_resolvers_operations_for_nested_objects::generate_name_for_nested_object_operation; use crate::refetchable_fragment::RefetchableFragment; use crate::refetchable_fragment::REFETCHABLE_NAME; use crate::relay_resolvers::RELAY_RESOLVER_DIRECTIVE_NAME; @@ -56,7 +55,6 @@ lazy_static! { // This gets attached to fragment which defines the selection in the generated query pub static ref CLIENT_EDGE_GENERATED_FRAGMENT_KEY: DirectiveName = DirectiveName("__clientEdgeGeneratedFragment".intern()); pub static ref CLIENT_EDGE_WATERFALL_DIRECTIVE_NAME: DirectiveName = DirectiveName("waterfall".intern()); - pub static ref RELAY_RESOLVER_IS_OUTPUT_TYPE: ArgumentName = ArgumentName("is_output_type".intern()); } /// Directive added to inline fragments created by the transform. The inline @@ -75,7 +73,6 @@ pub enum ClientEdgeMetadataDirective { ClientObject { type_name: StringKey, unique_id: u32, - normalization_operation: Option>, }, } associated_data_impl!(ClientEdgeMetadataDirective); @@ -355,19 +352,6 @@ impl<'program, 'sc> ClientEdgesTransform<'program, 'sc> { )); } - let is_resolver_with_output_type = resolver_directive - .and_then(|directive| directive.arguments.named(*RELAY_RESOLVER_IS_OUTPUT_TYPE)) - .is_some(); - - let normalization_operation_name = if is_resolver_with_output_type { - Some(generate_name_for_nested_object_operation( - &self.program.schema, - self.program.schema.field(field.definition().item), - )) - } else { - None - }; - match edge_to_type { Type::Interface(_) => { self.errors.push(Diagnostic::error( @@ -386,7 +370,6 @@ impl<'program, 'sc> ClientEdgesTransform<'program, 'sc> { Type::Object(object_id) => ClientEdgeMetadataDirective::ClientObject { type_name: schema.object(object_id).name.item, unique_id: self.get_key(), - normalization_operation: normalization_operation_name, }, _ => { panic!( diff --git a/compiler/crates/relay-transforms/src/generate_relay_resolvers_operations_for_nested_objects.rs b/compiler/crates/relay-transforms/src/generate_relay_resolvers_operations_for_nested_objects.rs index f7d8e6b9eaaa8..3116ab71f9c31 100644 --- a/compiler/crates/relay-transforms/src/generate_relay_resolvers_operations_for_nested_objects.rs +++ b/compiler/crates/relay-transforms/src/generate_relay_resolvers_operations_for_nested_objects.rs @@ -37,8 +37,8 @@ use crate::SplitOperationMetadata; use crate::ValidationMessage; lazy_static! { - pub static ref IS_OUTPUT_TYPE_ARGUMENT_NAME: ArgumentName = - ArgumentName("is_output_type".intern()); + pub static ref HAS_OUTPUT_TYPE_ARGUMENT_NAME: ArgumentName = + ArgumentName("has_output_type".intern()); } fn generate_fat_selections_from_type( @@ -272,9 +272,9 @@ pub fn generate_relay_resolvers_operations_for_nested_objects( } if let Some(directive) = field.directives.named(*RELAY_RESOLVER_DIRECTIVE_NAME) { - let is_output_type = - get_bool_argument_is_true(&directive.arguments, *IS_OUTPUT_TYPE_ARGUMENT_NAME); - if !is_output_type { + let has_output_type = + get_bool_argument_is_true(&directive.arguments, *HAS_OUTPUT_TYPE_ARGUMENT_NAME); + if !has_output_type { continue; } diff --git a/compiler/crates/relay-transforms/src/relay_resolvers.rs b/compiler/crates/relay-transforms/src/relay_resolvers.rs index c598ca36a73b3..065c133e083a1 100644 --- a/compiler/crates/relay-transforms/src/relay_resolvers.rs +++ b/compiler/crates/relay-transforms/src/relay_resolvers.rs @@ -22,6 +22,7 @@ use graphql_ir::FragmentDefinitionName; use graphql_ir::FragmentSpread; use graphql_ir::InlineFragment; use graphql_ir::LinkedField; +use graphql_ir::OperationDefinitionName; use graphql_ir::Program; use graphql_ir::ScalarField; use graphql_ir::Selection; @@ -38,6 +39,7 @@ use schema::Field; use schema::Schema; use super::ValidationMessage; +use crate::generate_relay_resolvers_operations_for_nested_objects::generate_name_for_nested_object_operation; use crate::ClientEdgeMetadata; use crate::FragmentAliasMetadata; use crate::RequiredMetadataDirective; @@ -66,6 +68,15 @@ lazy_static! { pub static ref RELAY_RESOLVER_IMPORT_PATH_ARGUMENT_NAME: ArgumentName = ArgumentName("import_path".intern()); pub static ref RELAY_RESOLVER_LIVE_ARGUMENT_NAME: ArgumentName = ArgumentName("live".intern()); + pub static ref RELAY_RESOLVER_IS_OUTPUT_TYPE: ArgumentName = + ArgumentName("has_output_type".intern()); +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +pub struct ResolverNormalizationInfo { + pub type_name: StringKey, + pub plural: bool, + pub normalization_operation: WithLocation, } #[derive(Clone, Debug, PartialEq, Eq, Hash)] @@ -75,6 +86,7 @@ struct RelayResolverFieldMetadata { fragment_name: Option, field_path: StringKey, live: bool, + normalization_info: Option, } associated_data_impl!(RelayResolverFieldMetadata); @@ -87,6 +99,7 @@ pub struct RelayResolverMetadata { pub field_path: StringKey, pub field_arguments: Vec, pub live: bool, + pub normalization_info: Option, } associated_data_impl!(RelayResolverMetadata); @@ -156,6 +169,7 @@ impl<'program> RelayResolverSpreadTransform<'program> { field_path: field_metadata.field_path, field_arguments, live: field_metadata.live, + normalization_info: field_metadata.normalization_info.clone(), }; let mut new_directives: Vec = vec![resolver_metadata.into()]; @@ -299,6 +313,7 @@ impl<'program> RelayResolverFieldTransform<'program> { fragment_name, import_path, live, + has_output_type, }) => { let mut non_required_directives = field.directives().iter().filter(|directive| { @@ -328,12 +343,28 @@ impl<'program> RelayResolverFieldTransform<'program> { } let parent_type = field_type.parent_type.unwrap(); + let normalization_info = if has_output_type { + let normalization_operation = generate_name_for_nested_object_operation( + &self.program.schema, + self.program.schema.field(field.definition().item), + ); + + Some(ResolverNormalizationInfo { + type_name: self.program.schema.get_type_name(field_type.type_.inner()), + plural: field_type.type_.is_list(), + normalization_operation, + }) + } else { + None + }; + let resolver_field_metadata = RelayResolverFieldMetadata { import_path, field_parent_type: self.program.schema.get_type_name(parent_type), fragment_name, field_path: self.path.join(".").intern(), live, + normalization_info, }; let mut directives: Vec = field.directives().to_vec(); @@ -448,6 +479,7 @@ struct ResolverInfo { fragment_name: Option, import_path: StringKey, live: bool, + has_output_type: bool, } fn get_resolver_info( @@ -475,11 +507,13 @@ fn get_resolver_info( error_location, )?; let live = get_bool_argument_is_true(arguments, *RELAY_RESOLVER_LIVE_ARGUMENT_NAME); - + let has_output_type = + get_bool_argument_is_true(arguments, *RELAY_RESOLVER_IS_OUTPUT_TYPE); Ok(ResolverInfo { fragment_name, import_path, live, + has_output_type, }) }) } diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment-no-type-condition.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment-no-type-condition.expected index af615f4905db1..33982ff537462 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment-no-type-condition.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment-no-type-condition.expected @@ -43,6 +43,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -66,6 +67,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment.expected index 1360d348c7aed..c928cd917378d 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-inline-fragment.expected @@ -48,6 +48,7 @@ fragment Foo_node on Node { # field_path: "author.best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -73,6 +74,7 @@ fragment Foo_node on Node { # field_path: "author.best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-to-client-object.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-to-client-object.expected index e70aa78b8af44..7f3bf7733be00 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-to-client-object.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-to-client-object.expected @@ -28,7 +28,6 @@ fragment Foo_user on User { # ClientObject { # type_name: "ClientOnlyType", # unique_id: 0, - # normalization_operation: None, # } { ...BestFriendResolverFragment_name @__RelayResolverMetadata @@ -40,6 +39,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } best_friend { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-variables.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-variables.expected index 17e34f4612faa..afec8b18199c1 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-variables.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-variables.expected @@ -35,6 +35,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-with-required.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-with-required.expected index f971745f1d5f6..9dc13fd358cee 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-with-required.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-with-required.expected @@ -39,6 +39,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall @required(action: NONE) best_friend @waterfall @required(action: NONE) { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-within-non-client-edge.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-within-non-client-edge.expected index c432f897f1bd9..4cd0c364fe034 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-within-non-client-edge.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge-within-non-client-edge.expected @@ -38,6 +38,7 @@ fragment Foo_user on User { # field_path: "nearest_neighbor.best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge.expected index 4e5ced2307c83..4e9efb0addf0d 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/client-edge.expected @@ -35,6 +35,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges-with-variables.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges-with-variables.expected index bd1a948152156..c9383b686de2b 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges-with-variables.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges-with-variables.expected @@ -39,6 +39,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -58,6 +59,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -96,6 +98,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__clientEdgeGe # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges.expected index 52d16e8196aef..be28697dcf27e 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/nested-client-edges.expected @@ -37,6 +37,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -55,6 +56,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { @@ -91,6 +93,7 @@ fragment RefetchableClientEdgeQuery_Foo_user_best_friend on User @__clientEdgeGe # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } @waterfall best_friend @waterfall { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.expected b/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.expected index dd8a71fe47deb..8463b836034af 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.expected +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.expected @@ -16,7 +16,7 @@ type ClientUser { } extend type User { - best_friend: ClientUser @relay_resolver(fragment_name: "BestFriendResolverFragment_name", import_path: "BestFriendResolver", is_output_type: true) + best_friend: ClientUser @relay_resolver(fragment_name: "BestFriendResolverFragment_name", import_path: "BestFriendResolver", has_output_type: true) } ==================================== OUTPUT =================================== fragment BestFriendResolverFragment_name on User { @@ -28,14 +28,6 @@ fragment Foo_user on User { # ClientObject { # type_name: "ClientUser", # unique_id: 0, - # normalization_operation: Some( - # WithLocation { - # location: :59:70, - # item: OperationDefinitionName( - # "User__best_friend$normalization", - # ), - # }, - # ), # } { ...BestFriendResolverFragment_name @__RelayResolverMetadata @@ -47,6 +39,18 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: Some( + # ResolverNormalizationInfo { + # type_name: "ClientUser", + # plural: false, + # normalization_operation: WithLocation { + # location: :59:70, + # item: OperationDefinitionName( + # "User__best_friend$normalization", + # ), + # }, + # }, + # ), # } best_friend { diff --git a/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.graphql b/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.graphql index 0c03b2989862f..7e69399018fc5 100644 --- a/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.graphql +++ b/compiler/crates/relay-transforms/tests/client_edges/fixtures/output-type.graphql @@ -15,5 +15,5 @@ type ClientUser { } extend type User { - best_friend: ClientUser @relay_resolver(fragment_name: "BestFriendResolverFragment_name", import_path: "BestFriendResolver", is_output_type: true) + best_friend: ClientUser @relay_resolver(fragment_name: "BestFriendResolverFragment_name", import_path: "BestFriendResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.expected index cfbcabb5b85b1..434e914777f3b 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.expected @@ -23,13 +23,13 @@ input PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Invalid @RelayResolver output type for field `pop_star_name`. Got input object `PopStarName`. output-type-input.invalid.graphql:7:3 6 │ extend type User { - 7 │ pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + 7 │ pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) │ ^^^^^^^^^^^^^ 8 │ } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.graphql index 623e52c7e977d..0be07ec48792d 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-input.invalid.graphql @@ -22,5 +22,5 @@ input PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.expected index 18e435003ad38..1965bea2d8cdc 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.expected @@ -18,13 +18,13 @@ fragment PopStarNameResolverFragment_name on User { # %extensions% extend type User { - pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ @RelayResolver scalar type `String` for field `pop_star_name` is not supported as @outputType, yet. output-type-scalar.invalid.graphql:4:3 3 │ extend type User { - 4 │ pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + 4 │ pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) │ ^^^^^^^^^^^^^ 5 │ } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.graphql index 1bb004c83342f..0a9b599de2293 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-scalar.invalid.graphql @@ -17,5 +17,5 @@ fragment PopStarNameResolverFragment_name on User { # %extensions% extend type User { - pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: String @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.expected index 979bc1e0db1e9..d4d3b0f4383d9 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.expected @@ -14,7 +14,7 @@ type MyThing { } extend type User { - my_things: [MyThing] @relay_resolver(import_path: "MyThingResolver", is_output_type: true) + my_things: [MyThing] @relay_resolver(import_path: "MyThingResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Arguments are not supported in the fields on the @outputType in @RelayResolvers. You'll need to expose these fields using @RelayResolver for them. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.graphql index e6ff047570085..37deebb8ad1f6 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-arguments.graphql @@ -13,5 +13,5 @@ type MyThing { } extend type User { - my_things: [MyThing] @relay_resolver(import_path: "MyThingResolver", is_output_type: true) + my_things: [MyThing] @relay_resolver(import_path: "MyThingResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.expected index 5285b16f7a38d..fb14b9bb8a826 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.expected @@ -14,7 +14,7 @@ type Todo { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Field name `id` is reserved for strong objects (objects that implement Node interface). Defining `id` fields is not currently supported on @RelayResolver with @outputType. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.graphql index 10b13373a82f0..7f643d71eecb3 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-id.graphql @@ -13,5 +13,5 @@ type Todo { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.expected index b5b450bd655f6..105bf7a1529e0 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.expected @@ -28,7 +28,7 @@ interface IStageName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ @RelayResolver interface type `IStageName` for field `also_a_stage_name` is not supported as @outputType, yet. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.graphql index 0fb65a57ad8a7..fa061994cde75 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-interface.invalid.graphql @@ -27,5 +27,5 @@ interface IStageName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.expected index ea4335b3f570f..e50a0e33f16b4 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.expected @@ -20,7 +20,7 @@ type TodoDependencies { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ @RelayResolver type recursion detected for the output type `TodoDependencies`. This is not supported for `@outputType` resolvers. If you want to model a connection between two entities of the same GraphQL type, consider creating a new Relay Resolver with `@edgeTo` annotation. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.graphql index dc4d9870a87c1..2bdfa3de85634 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-recursion.graphql @@ -19,5 +19,5 @@ type TodoDependencies { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.expected index 7c8b4cbafb24b..3177be3c975d3 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.expected @@ -14,7 +14,7 @@ type PageWrapper { } extend type User { - page: PageWrapper @relay_resolver(import_path: "TodoResolver", is_output_type: true) + page: PageWrapper @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Field `page` has output type `Page`. `Page` is a server type, and server types cannot be used with @outputType on @RelayResolver. Edges to server types can be exposed with @edgeTo and @waterfall. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.graphql index 4318d5626a6c5..bd75c8907ab88 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-nested-server-type.graphql @@ -13,5 +13,5 @@ type PageWrapper { } extend type User { - page: PageWrapper @relay_resolver(import_path: "TodoResolver", is_output_type: true) + page: PageWrapper @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.expected index 061c0fe376aad..fbc179022b2ed 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.expected @@ -15,7 +15,7 @@ type Todo { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ @RelayResolver type recursion detected for the output type `Todo`. This is not supported for `@outputType` resolvers. If you want to model a connection between two entities of the same GraphQL type, consider creating a new Relay Resolver with `@edgeTo` annotation. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.graphql index 5bea5ba4c53d5..a0a4849ab8d4a 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-recursion.graphql @@ -14,5 +14,5 @@ type Todo { } extend type User { - todo: [Todo] @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: [Todo] @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.expected index 30c331d727f42..7a42a15a98034 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.expected @@ -27,7 +27,7 @@ extend type PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } ==================================== OUTPUT =================================== query User__pop_star_name$normalization @__splitOperation(parentDocuments: [], rawResponseType: null) { diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.graphql index d53e0c5c534cd..9e4da17f3687b 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-relay-resolver-fields.graphql @@ -26,5 +26,5 @@ extend type PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.expected index ed158a85c8315..0221f3530af16 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.expected @@ -10,13 +10,13 @@ fragment Foo_user on User { # %extensions% extend type User { - page: Page @relay_resolver(import_path: "TodoResolver", is_output_type: true) + page: Page @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Field `page` has output type `Page`. `Page` is a server type, and server types cannot be used with @outputType on @RelayResolver. Edges to server types can be exposed with @edgeTo and @waterfall. output-type-with-server-type.graphql:4:3 3 │ extend type User { - 4 │ page: Page @relay_resolver(import_path: "TodoResolver", is_output_type: true) + 4 │ page: Page @relay_resolver(import_path: "TodoResolver", has_output_type: true) │ ^^^^ 5 │ } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.graphql index 66a3460791f60..33eea2c72f73a 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-server-type.graphql @@ -9,5 +9,5 @@ fragment Foo_user on User { # %extensions% extend type User { - page: Page @relay_resolver(import_path: "TodoResolver", is_output_type: true) + page: Page @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.expected index 5a012e9bdb5a4..f0f9ff502ac02 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.expected @@ -18,7 +18,7 @@ type Todo { } extend type User { - todo: Todo @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: Todo @relay_resolver(import_path: "TodoResolver", has_output_type: true) } ==================================== ERROR ==================================== ✖︎ Field name `id` is reserved for strong objects (objects that implement Node interface). Defining `id` fields is not currently supported on @RelayResolver with @outputType. diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.graphql index 1a2b8c8b237a8..bfd1f4710f5ff 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type-with-type-with-id.graphql @@ -17,5 +17,5 @@ type Todo { } extend type User { - todo: Todo @relay_resolver(import_path: "TodoResolver", is_output_type: true) + todo: Todo @relay_resolver(import_path: "TodoResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.expected b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.expected index ecaaa8bb44239..519805111e605 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.expected +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.expected @@ -23,7 +23,7 @@ type PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } ==================================== OUTPUT =================================== query User__pop_star_name$normalization @__splitOperation(parentDocuments: [], rawResponseType: null) { diff --git a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.graphql b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.graphql index 2824e20b232d9..da7a1dac5efea 100644 --- a/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.graphql +++ b/compiler/crates/relay-transforms/tests/generate_relay_resolvers_operations_for_nested_objects/fixtures/output-type.graphql @@ -22,5 +22,5 @@ type PopStarName { } extend type User { - pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", is_output_type: true) + pop_star_name: PopStarName @relay_resolver(fragment_name: "PopStarNameResolverFragment_name", import_path: "PopStarNameResolver", has_output_type: true) } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/field-alias.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/field-alias.expected index 74a8c84994f0e..f93ed00fab788 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/field-alias.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/field-alias.expected @@ -31,6 +31,7 @@ fragment Foo_user on User { # field_path: "poppy", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/missing-fragment-name.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/missing-fragment-name.expected index b4685aeed6c2b..0bc2b0c3ce5b3 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/missing-fragment-name.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/missing-fragment-name.expected @@ -19,6 +19,7 @@ fragment Foo_user on User { # field_path: "pop_star_name", # field_arguments: [], # live: true, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/multiple-relay-resolvers.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/multiple-relay-resolvers.expected index e88a49d4921fd..0d5ad5f34ce9d 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/multiple-relay-resolvers.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/multiple-relay-resolvers.expected @@ -35,6 +35,7 @@ fragment Foo_user on User { # field_path: "pop_star_name", # field_arguments: [], # live: false, + # normalization_info: None, # } ...HobbitNameResolverFragment_name @__RelayResolverMetadata @@ -46,6 +47,7 @@ fragment Foo_user on User { # field_path: "hobbit_name", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/nested-relay-resolver.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/nested-relay-resolver.expected index 885d997d6f06c..5a7ee6c3d451b 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/nested-relay-resolver.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/nested-relay-resolver.expected @@ -35,6 +35,7 @@ fragment Foo_user on User { # field_path: "hobbit_name", # field_arguments: [], # live: false, + # normalization_info: None, # } } @@ -50,6 +51,7 @@ fragment HobbitNameResolverFragment_name on User { # field_path: "pop_star_name", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-backing-client-edge.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-backing-client-edge.expected index 0d4d2f5363948..14c65cf220efe 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-backing-client-edge.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-backing-client-edge.expected @@ -33,6 +33,7 @@ fragment Foo_user on User { # field_path: "best_friend", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-field-and-fragment-arguments.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-field-and-fragment-arguments.expected index 4589b5e6bbdf8..1aac40cc67153 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-field-and-fragment-arguments.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-field-and-fragment-arguments.expected @@ -41,6 +41,7 @@ fragment Foo_user on User { # }, # ], # live: false, + # normalization_info: None, # } @arguments(fragment_arg: 1) } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-required.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-required.expected index 0f46d3ec288fc..1ecba18e9090f 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-required.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-required.expected @@ -29,6 +29,7 @@ fragment Foo_user on User { # field_path: "pop_star_name", # field_arguments: [], # live: false, + # normalization_info: None, # } @required(action: THROW) } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-within-named-inline-fragment.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-within-named-inline-fragment.expected index 3680f13766540..de267181ab6fd 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-within-named-inline-fragment.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver-within-named-inline-fragment.expected @@ -40,6 +40,7 @@ fragment Foo_user on Node { # field_path: "aliased_fragment.pop_star_name", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver.expected b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver.expected index e8cb1dd6d2664..8840582b98934 100644 --- a/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver.expected +++ b/compiler/crates/relay-transforms/tests/relay_resolvers/fixtures/relay-resolver.expected @@ -29,6 +29,7 @@ fragment Foo_user on User { # field_path: "pop_star_name", # field_arguments: [], # live: false, + # normalization_info: None, # } } diff --git a/packages/react-relay/__tests__/__generated__/ExampleWithOutputTypeTestQuery.graphql.js b/packages/react-relay/__tests__/__generated__/ExampleWithOutputTypeTestQuery.graphql.js index 0d8c61fc82a6d..5353d9b5994ef 100644 --- a/packages/react-relay/__tests__/__generated__/ExampleWithOutputTypeTestQuery.graphql.js +++ b/packages/react-relay/__tests__/__generated__/ExampleWithOutputTypeTestQuery.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<012a893fae28245c7cfaccf0b44f6bd0>> + * @generated SignedSource<> * @flow * @lightSyntaxTransform * @nogrep @@ -53,7 +53,12 @@ var node/*: ClientRequest*/ = { "kind": "RelayResolver", "name": "example_client_object", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/ExampleClientObjectResolver'), - "path": "example_client_object" + "path": "example_client_object", + "normalizationInfo": { + "concreteType": "ClientObject", + "plural": false, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__example_client_object$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -72,8 +77,7 @@ var node/*: ClientRequest*/ = { } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__example_client_object$normalization.graphql') + } } ], "type": "Query", diff --git a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestExceptionalProjectQuery.graphql.js b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestExceptionalProjectQuery.graphql.js index 6e5f5927b326a..aab407e2ae7f4 100644 --- a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestExceptionalProjectQuery.graphql.js +++ b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestExceptionalProjectQuery.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<7dc568a653144073f51c0cc7a94e11b5>> + * @generated SignedSource<<29b063a5c68107193a12034d01afd092>> * @flow * @lightSyntaxTransform * @nogrep @@ -72,7 +72,12 @@ return { "kind": "RelayLiveResolver", "name": "todos", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/QueryTodos'), - "path": "todos" + "path": "todos", + "normalizationInfo": { + "concreteType": "TodoConnection", + "plural": false, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todos$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -111,8 +116,7 @@ return { } ], "storageKey": "todos(first:10)" - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todos$normalization.graphql') + } } ], "type": "Query", diff --git a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestFragment.graphql.js b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestFragment.graphql.js index d558caa79aae3..cecb8a0725b4c 100644 --- a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestFragment.graphql.js +++ b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestFragment.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<533bb48724b1c0e25a9a96308886b696>> + * @generated SignedSource<<5dc58acce768c6c0fdbcc16f9ce85213>> * @flow * @lightSyntaxTransform * @nogrep @@ -68,7 +68,12 @@ var node/*: ReaderFragment*/ = { "kind": "RelayResolver", "name": "text", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/TodoTextResolver'), - "path": "text" + "path": "text", + "normalizationInfo": { + "concreteType": "TodoText", + "plural": false, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Todo__text$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -103,8 +108,7 @@ var node/*: ReaderFragment*/ = { } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Todo__text$normalization.graphql') + } }, { "args": null, diff --git a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestManyTodosQuery.graphql.js b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestManyTodosQuery.graphql.js index cb46d5554b6b6..309423155a817 100644 --- a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestManyTodosQuery.graphql.js +++ b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestManyTodosQuery.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<39750bad97c995763ea79f7bbabdb8d0>> + * @generated SignedSource<> * @flow * @lightSyntaxTransform * @nogrep @@ -75,7 +75,12 @@ return { "kind": "RelayResolver", "name": "many_todos", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/QueryManyTodos'), - "path": "many_todos" + "path": "many_todos", + "normalizationInfo": { + "concreteType": "Todo", + "plural": true, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__many_todos$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -92,8 +97,7 @@ return { } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__many_todos$normalization.graphql') + } } ], "type": "Query", @@ -109,10 +113,10 @@ return { "kind": "ClientExtension", "selections": [ { - "alias": null, - "args": null, - "kind": "ScalarField", - "name": "__id", + "name": "many_todos", + "args": (v1/*: any*/), + "fragment": null, + "kind": "RelayResolver", "storageKey": null } ] diff --git a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoQuery.graphql.js b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoQuery.graphql.js index 46eb38ab4ed19..aaabfaf01aadb 100644 --- a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoQuery.graphql.js +++ b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoQuery.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<> + * @generated SignedSource<<14bd9d75c6a49376caeb6b5f782c2592>> * @flow * @lightSyntaxTransform * @nogrep @@ -76,7 +76,12 @@ return { "kind": "RelayLiveResolver", "name": "todo", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/QueryTodo'), - "path": "todo" + "path": "todo", + "normalizationInfo": { + "concreteType": "Todo", + "plural": false, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todo$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -93,8 +98,7 @@ return { } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todo$normalization.graphql') + } } ], "type": "Query", diff --git a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoWithBlockedQuery.graphql.js b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoWithBlockedQuery.graphql.js index 5291123501f4f..d55a1e730dd8c 100644 --- a/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoWithBlockedQuery.graphql.js +++ b/packages/react-relay/__tests__/__generated__/RelayResolversWithOutputTypeTestTodoWithBlockedQuery.graphql.js @@ -6,7 +6,7 @@ * * @oncall relay * - * @generated SignedSource<<718d3485dcf9ba01884bddebcd1bc47f>> + * @generated SignedSource<<864dd3a4ed1c88af50f1007a30f666c0>> * @flow * @lightSyntaxTransform * @nogrep @@ -85,7 +85,12 @@ return { "kind": "RelayLiveResolver", "name": "todo", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/QueryTodo'), - "path": "todo" + "path": "todo", + "normalizationInfo": { + "concreteType": "Todo", + "plural": false, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todo$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -109,7 +114,12 @@ return { "kind": "RelayResolver", "name": "blocked_by", "resolverModule": require('./../../../relay-runtime/store/__tests__/resolvers/TodoBlockedByResolver'), - "path": "blocked_by" + "path": "blocked_by", + "normalizationInfo": { + "concreteType": "Todo", + "plural": true, + "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Todo__blocked_by$normalization.graphql') + } }, "linkedField": { "alias": null, @@ -126,13 +136,11 @@ return { } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Todo__blocked_by$normalization.graphql') + } } ], "storageKey": null - }, - "normalizationNode": require('./../../../relay-runtime/store/__tests__/resolvers/__generated__/Query__todo$normalization.graphql') + } } ], "type": "Query", diff --git a/packages/relay-runtime/store/RelayReader.js b/packages/relay-runtime/store/RelayReader.js index c8b9ea4991a4c..1eee17841ac99 100644 --- a/packages/relay-runtime/store/RelayReader.js +++ b/packages/relay-runtime/store/RelayReader.js @@ -44,7 +44,6 @@ import type { SelectorData, SingularReaderSelector, Snapshot, - ResolverNormalizationInfo, } from './RelayStoreTypes'; import type {Arguments} from './RelayStoreUtils'; import type {EvaluationResult, ResolverCache} from './ResolverCache'; @@ -129,7 +128,6 @@ class RelayReader { _resolverCache: ResolverCache; _resolverErrors: RelayResolverErrors; _fragmentName: string; - _resolverNormalizationInfo: ?ResolverNormalizationInfo; constructor( recordSource: RecordSource, @@ -154,7 +152,6 @@ class RelayReader { this._resolverCache = resolverCache; this._resolverErrors = []; this._fragmentName = selector.node.name; - this._resolverNormalizationInfo = null; } read(): Snapshot { @@ -618,7 +615,6 @@ class RelayReader { this._variables, evaluate, getDataForResolverFragment, - this._resolverNormalizationInfo, ); // The resolver's root fragment (if there is one) may be missing data, have @@ -695,12 +691,8 @@ class RelayReader { ); const applicationName = backingField.alias ?? backingField.name; - - const prevResolverNormalizationInfo = this._resolverNormalizationInfo; - this._resolverNormalizationInfo = getResolverNormalizationInfo(field); const backingFieldData = {}; this._traverseSelections([backingField], record, backingFieldData); - this._resolverNormalizationInfo = prevResolverNormalizationInfo; let destinationDataID = backingFieldData[applicationName]; if (destinationDataID == null || isSuspenseSentinel(destinationDataID)) { @@ -723,7 +715,7 @@ class RelayReader { if (field.kind === CLIENT_EDGE_TO_CLIENT_OBJECT) { // Client objects might use ids that are not globally unique and instead are just // local within their type. ResolverCache will derive a namespaced ID for us. - if (field.normalizationNode == null) { + if (backingField.normalizationInfo == null) { // @edgeTo case where we need to ensure that the record has `id` field if (field.linkedField.plural) { // $FlowFixMe[prop-missing] @@ -1268,21 +1260,4 @@ function getResolverValue( return [resolverResult, resolverError]; } -function getResolverNormalizationInfo( - field: ReaderClientEdgeToClientObject | ReaderClientEdgeToServerObject, -): ResolverNormalizationInfo | null { - if ( - field.kind === 'ClientEdgeToClientObject' && - field.normalizationNode != null - ) { - return { - normalizationNode: field.normalizationNode, - concreteType: field.concreteType, - plural: field.linkedField.plural, - }; - } else { - return null; - } -} - module.exports = {read}; diff --git a/packages/relay-runtime/store/RelayStoreTypes.js b/packages/relay-runtime/store/RelayStoreTypes.js index fdc1405cad6cb..c5fcfe759c2c0 100644 --- a/packages/relay-runtime/store/RelayStoreTypes.js +++ b/packages/relay-runtime/store/RelayStoreTypes.js @@ -149,12 +149,6 @@ export type MissingLiveResolverField = { +liveStateID: DataID, }; -export type ResolverNormalizationInfo = { - +concreteType: string, - +normalizationNode: NormalizationSelectableNode, - +plural: boolean, -}; - /** * A representation of a selector and its results at a particular point in time. */ diff --git a/packages/relay-runtime/store/ResolverCache.js b/packages/relay-runtime/store/ResolverCache.js index b7e034e5cf430..508cadf764356 100644 --- a/packages/relay-runtime/store/ResolverCache.js +++ b/packages/relay-runtime/store/ResolverCache.js @@ -22,7 +22,6 @@ import type { RelayResolverError, SingularReaderSelector, Snapshot, - ResolverNormalizationInfo, } from './RelayStoreTypes'; const recycleNodesInto = require('../util/recycleNodesInto'); @@ -62,7 +61,6 @@ export interface ResolverCache { variables: Variables, evaluate: () => EvaluationResult, getDataForResolverFragment: GetDataForResolverFragmentFn, - normalizationObject: ?ResolverNormalizationInfo, ): [ ?T /* Answer */, ?DataID /* Seen record */, @@ -86,7 +84,6 @@ class NoopResolverCache implements ResolverCache { variables: Variables, evaluate: () => EvaluationResult, getDataForResolverFragment: GetDataForResolverFragmentFn, - normalizationObject: ?ResolverNormalizationInfo, ): [ ?T /* Answer */, ?DataID /* Seen record */, @@ -142,7 +139,6 @@ class RecordResolverCache implements ResolverCache { variables: Variables, evaluate: () => EvaluationResult, getDataForResolverFragment: GetDataForResolverFragmentFn, - normalizationObject: ?ResolverNormalizationInfo, ): [ ?T /* Answer */, ?DataID /* Seen record */, diff --git a/packages/relay-runtime/store/experimental-live-resolvers/LiveResolverCache.js b/packages/relay-runtime/store/experimental-live-resolvers/LiveResolverCache.js index cdab8b1f5ed83..baf959c813a73 100644 --- a/packages/relay-runtime/store/experimental-live-resolvers/LiveResolverCache.js +++ b/packages/relay-runtime/store/experimental-live-resolvers/LiveResolverCache.js @@ -14,6 +14,7 @@ import type { ReaderRelayLiveResolver, ReaderRelayResolver, + ResolverNormalizationInfo, } from '../../util/ReaderNode'; import type {DataID, Variables} from '../../util/RelayRuntimeTypes'; import type {NormalizationOptions} from '../RelayResponseNormalizer'; @@ -24,7 +25,6 @@ import type { RelayResolverError, SingularReaderSelector, Snapshot, - ResolverNormalizationInfo, } from '../RelayStoreTypes'; import type { EvaluationResult, @@ -102,7 +102,6 @@ class LiveResolverCache implements ResolverCache { variables: Variables, evaluate: () => EvaluationResult, getDataForResolverFragment: GetDataForResolverFragmentFn, - resolverNoramlizationInfo: ?ResolverNormalizationInfo, ): [ ?T /* Answer */, ?DataID /* Seen record */, @@ -160,9 +159,8 @@ class LiveResolverCache implements ResolverCache { linkedRecord, linkedID, liveState, - field.path, + field, variables, - resolverNoramlizationInfo, ); } else { if (__DEV__) { @@ -189,9 +187,8 @@ class LiveResolverCache implements ResolverCache { this._setRelayResolverValue( linkedRecord, evaluationResult.resolverResult, - field.path, + field, variables, - resolverNoramlizationInfo, ); } RelayModernRecord.setValue( @@ -267,9 +264,8 @@ class LiveResolverCache implements ResolverCache { this._setRelayResolverValue( linkedRecord, liveState.read(), - field.path, + field, variables, - resolverNoramlizationInfo, ); // Mark the resolver as clean again. @@ -340,9 +336,8 @@ class LiveResolverCache implements ResolverCache { linkedRecord: Record, linkedID: DataID, liveState: LiveState, - fieldPath: string, + field: ReaderRelayLiveResolver, variables: Variables, - resolverNoramlizationInfo: ?ResolverNormalizationInfo, ): void { // Subscribe to future values // Note: We subscribe before reading, since subscribing could potentially @@ -362,9 +357,8 @@ class LiveResolverCache implements ResolverCache { this._setRelayResolverValue( linkedRecord, liveState.read(), - fieldPath, + field, variables, - resolverNoramlizationInfo, ); // Mark the field as clean. @@ -432,15 +426,15 @@ class LiveResolverCache implements ResolverCache { _setRelayResolverValue( resolverRecord: Record, value: mixed, - fieldPath: string, + field: ReaderRelayResolver | ReaderRelayLiveResolver, variables: Variables, - resolverNoramlizationInfo: ?ResolverNormalizationInfo, ): void { - if (value != null && resolverNoramlizationInfo != null) { + const normalizationInfo = field.normalizationInfo; + if (value != null && normalizationInfo != null) { const resolverDataID = RelayModernRecord.getDataID(resolverRecord); let resolverValue: DataID | Array; const target = this._getRecordSource(); - if (resolverNoramlizationInfo.plural) { + if (normalizationInfo.plural) { invariant( Array.isArray(value), '_setRelayResolverValue: Expected array value for plural @outputType resolver.', @@ -465,16 +459,17 @@ class LiveResolverCache implements ResolverCache { // there is only one path to the records created from the // @outputType payload. const outputTypeDataID = generateClientObjectClientID( - resolverNoramlizationInfo.concreteType, + normalizationInfo.concreteType, `${resolverDataID}:${ii}`, ); const source = normalizeOutputTypeValue( outputTypeDataID, currentValue, variables, - resolverNoramlizationInfo, - this._store.__getNormalizationOptions([`${fieldPath}.${ii}`]), + normalizationInfo, + this._store.__getNormalizationOptions([`${field.path}.${ii}`]), ); + // If, the `target` source (the current store) // does not have records for the @outputType // we need add them directly to the store, @@ -509,15 +504,15 @@ class LiveResolverCache implements ResolverCache { '_setRelayResolverValue: Expected object value as the payload for the @outputType resolver.', ); const outputTypeDataID = generateClientObjectClientID( - resolverNoramlizationInfo.concreteType, + normalizationInfo.concreteType, resolverDataID, ); const source = normalizeOutputTypeValue( outputTypeDataID, value, variables, - resolverNoramlizationInfo, - this._store.__getNormalizationOptions([fieldPath]), + normalizationInfo, + this._store.__getNormalizationOptions([field.path]), ); if (target.has(outputTypeDataID)) { this._store.__publishSourcesAndNotifyOnlyUpdatedIds([source]); @@ -688,7 +683,7 @@ function normalizeOutputTypeValue( outputTypeDataID: DataID, value: {...}, variables: Variables, - resolverNoramlizationInfo: ResolverNormalizationInfo, + resolverNormalizationInfo: ResolverNormalizationInfo, normalizationOptions: NormalizationOptions, ): RecordSource { const source = RelayRecordSource.create(); @@ -696,11 +691,11 @@ function normalizeOutputTypeValue( outputTypeDataID, RelayModernRecord.create( outputTypeDataID, - resolverNoramlizationInfo.concreteType, + resolverNormalizationInfo.concreteType, ), ); const selector = createNormalizationSelector( - resolverNoramlizationInfo.normalizationNode, + resolverNormalizationInfo.normalizationNode, outputTypeDataID, variables, ); diff --git a/packages/relay-runtime/util/ReaderNode.js b/packages/relay-runtime/util/ReaderNode.js index 0b2eaa8e33213..29e23713ce18b 100644 --- a/packages/relay-runtime/util/ReaderNode.js +++ b/packages/relay-runtime/util/ReaderNode.js @@ -246,6 +246,12 @@ type ResolverFunction = (...args: Array) => mixed; // flowlint-line unclear // With ES6 imports, a resolver function might be exported under the `default` key. type ResolverModule = ResolverFunction | {default: ResolverFunction}; +export type ResolverNormalizationInfo = { + +concreteType: string, + +plural: boolean, + +normalizationNode: NormalizationSelectableNode, +}; + export type ReaderRelayResolver = { +kind: 'RelayResolver', +alias: ?string, @@ -254,6 +260,7 @@ export type ReaderRelayResolver = { +fragment: ?ReaderFragmentSpread, +path: string, +resolverModule: ResolverModule, + +normalizationInfo?: ResolverNormalizationInfo, }; export type ReaderRelayLiveResolver = { @@ -264,6 +271,7 @@ export type ReaderRelayLiveResolver = { +fragment: ?ReaderFragmentSpread, +path: string, +resolverModule: ResolverModule, + +normalizationInfo?: ResolverNormalizationInfo, }; export type ReaderClientEdgeToClientObject = { @@ -274,7 +282,6 @@ export type ReaderClientEdgeToClientObject = { | ReaderRelayResolver | ReaderRelayLiveResolver | ReaderClientExtension, - +normalizationNode?: NormalizationSelectableNode, }; export type ReaderClientEdgeToServerObject = {