From 4e2ba8e534e59d4f337ea6f088eed3149e7e111d Mon Sep 17 00:00:00 2001 From: ellisandrews-toast Date: Wed, 15 Jul 2026 15:26:17 -0400 Subject: [PATCH 1/2] Add unit test for Relationship#parent_relationship to_final_form handling --- .../schema_elements/relationship_spec.rb | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb diff --git a/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb b/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb new file mode 100644 index 000000000..ed1161de1 --- /dev/null +++ b/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb @@ -0,0 +1,43 @@ +# Copyright 2024 - 2026 Block, Inc. +# +# Use of this source code is governed by an MIT-style +# license that can be found in the LICENSE file or at +# https://opensource.org/licenses/MIT. +# +# frozen_string_literal: true + +require "elastic_graph/schema_artifacts/runtime_metadata/schema_element_names" +require "elastic_graph/schema_definition/api" +require "elastic_graph/spec_support/schema_definition_helpers" + +module ElasticGraph + module SchemaDefinition + module SchemaElements + RSpec.describe Relationship do + describe "#parent_relationship" do + it "stores the parent type ref in its final form, applying any `type_name_overrides` rename" do + expect(stored_parent_type_ref(type_name_overrides: {"Team" => "RenamedTeam"}).name).to eq "RenamedTeam" + end + + it "leaves the parent type name unchanged when no `type_name_overrides` applies to it" do + expect(stored_parent_type_ref(type_name_overrides: {}).name).to eq "Team" + end + end + + def stored_parent_type_ref(type_name_overrides:) + schema_elements = SchemaArtifacts::RuntimeMetadata::SchemaElementNames.new(form: "snake_case") + api = API.new(schema_elements, true, type_name_overrides: type_name_overrides) + + api.object_type "Player" do |t| + t.field "id", "ID!" + t.relates_to_one "statLine", "StatLine", via: "playerId", dir: :in, indexing_only: true do |r| + r.parent_relationship "Team", "statLines" + end + end + + api.state.object_types_by_name.fetch("Player").relationships_by_name.fetch("statLine").parent_ref.type_ref + end + end + end + end +end From ffbf64ea247df2f21f71463d64d1d6479624c7fc Mon Sep 17 00:00:00 2001 From: ellisandrews-toast Date: Mon, 20 Jul 2026 16:15:50 -0400 Subject: [PATCH 2/2] Move to_final_form coverage into update_targets_spec per review feedback --- .../update_targets_spec.rb | 14 ++++-- .../schema_elements/relationship_spec.rb | 43 ------------------- 2 files changed, 11 insertions(+), 46 deletions(-) delete mode 100644 elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb diff --git a/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/object_types_by_name/update_targets_spec.rb b/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/object_types_by_name/update_targets_spec.rb index 5face3146..b165d56aa 100644 --- a/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/object_types_by_name/update_targets_spec.rb +++ b/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/runtime_metadata/object_types_by_name/update_targets_spec.rb @@ -1501,6 +1501,12 @@ def raise_error_about_workspace_relationship(details, sourced_fields: true) expect_statline_update_target_with(metadata) end + it "resolves the parent type by its overridden name when `type_name_overrides` renames it" do + metadata = nested_sourced_from_schema(type_name_overrides: {"Team" => "RenamedTeam"}) + + expect_statline_update_target_with(metadata, type: "RenamedTeam") + end + it "discovers an embedding field declared with `indexing_only: true`" do # An `indexing_only: true` field is absent from `graphql_fields_by_name` but present in # `indexing_fields_by_name_in_index`, so this only resolves when the latter is used. @@ -1917,6 +1923,7 @@ def nested_update_targets_by_relationship(metadata) def expect_statline_update_target_with( metadata, relationship: "players.statLine", + type: "Team", routing_value_source: nil, rollover_timestamp_value_source: nil, field_params: {"goals" => dynamic_param_with(source_path: "goals", cardinality: :one)}, @@ -1926,7 +1933,7 @@ def expect_statline_update_target_with( expect(targets.keys).to contain_exactly(relationship) target = targets.fetch(relationship) - expect(target.type).to eq "Team" + expect(target.type).to eq type expect(target.relationship).to eq relationship expect(target.script_id).to eq(INDEX_DATA_UPDATE_SCRIPT_ID) expect(target.id_source).to eq "teamId" @@ -1954,10 +1961,11 @@ def nested_sourced_from_schema( player_goals_type: "Int", player_goals_source: "goals", player_statline_dir: :in, - player_statline_via: "playerId" + player_statline_via: "playerId", + type_name_overrides: {} ) # `StatLine` is the source type, so its metadata carries the nested update targets we assert on. - object_type_metadata_for "StatLine" do |s| + object_type_metadata_for "StatLine", type_name_overrides: type_name_overrides do |s| if embed_players_under s.object_type s.state.type_ref(embed_players_under).fully_unwrapped.name do |t| t.field "players", players_field do |f| diff --git a/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb b/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb deleted file mode 100644 index ed1161de1..000000000 --- a/elasticgraph-schema_definition/spec/unit/elastic_graph/schema_definition/schema_elements/relationship_spec.rb +++ /dev/null @@ -1,43 +0,0 @@ -# Copyright 2024 - 2026 Block, Inc. -# -# Use of this source code is governed by an MIT-style -# license that can be found in the LICENSE file or at -# https://opensource.org/licenses/MIT. -# -# frozen_string_literal: true - -require "elastic_graph/schema_artifacts/runtime_metadata/schema_element_names" -require "elastic_graph/schema_definition/api" -require "elastic_graph/spec_support/schema_definition_helpers" - -module ElasticGraph - module SchemaDefinition - module SchemaElements - RSpec.describe Relationship do - describe "#parent_relationship" do - it "stores the parent type ref in its final form, applying any `type_name_overrides` rename" do - expect(stored_parent_type_ref(type_name_overrides: {"Team" => "RenamedTeam"}).name).to eq "RenamedTeam" - end - - it "leaves the parent type name unchanged when no `type_name_overrides` applies to it" do - expect(stored_parent_type_ref(type_name_overrides: {}).name).to eq "Team" - end - end - - def stored_parent_type_ref(type_name_overrides:) - schema_elements = SchemaArtifacts::RuntimeMetadata::SchemaElementNames.new(form: "snake_case") - api = API.new(schema_elements, true, type_name_overrides: type_name_overrides) - - api.object_type "Player" do |t| - t.field "id", "ID!" - t.relates_to_one "statLine", "StatLine", via: "playerId", dir: :in, indexing_only: true do |r| - r.parent_relationship "Team", "statLines" - end - end - - api.state.object_types_by_name.fetch("Player").relationships_by_name.fetch("statLine").parent_ref.type_ref - end - end - end - end -end