Skip to content

Rename document_type_stored_in → document_types_stored_in returning Set#1159

Merged
myronmarston merged 5 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/document-types-stored-in
Apr 30, 2026
Merged

Rename document_type_stored_in → document_types_stored_in returning Set#1159
myronmarston merged 5 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/document-types-stored-in

Conversation

@marcdaniels-toast
Copy link
Copy Markdown
Contributor

This PR was created as a companion to #1150 (an initial step). It paves the way for the non_subtypes_in_shared_index method by ensuring the GraphQL schema correctly tracks all document types per index, rather than only the first one seen.

indexed_document_types_by_index_definition_name now returns Set per index

Previously, the hash stored only the first type seen for a given index name (via ||=). With index inheritance, multiple concrete types can share the same index — so the old approach would non-deterministically drop all but one.

Changed to accumulate all indexed document types per index into a Set. This is required for non_subtypes_in_shared_index to work correctly: that method uses this hash to enumerate all types sharing an index when deciding whether a __typename filter is needed on abstract type queries. With the old approach, other types sharing the same index could be silently omitted, leading to incorrect or missing __typename filters.

document_type_stored_indocument_types_stored_in

Renamed to reflect that the method now returns a Set[Type] rather than a single Type. Updated the two callers:

  • graphql_adapter_builder (resolve_type): uses .first — safe here because this branch is only reached for individually-indexed types (no __typename in the document means no shared index), so the set always contains exactly one type.
  • search_response_adapter_builder (all_highlights): now prefers __typename from the document source when present. Documents stored in a shared index carry __typename to identify their concrete type; using it directly ensures highlight field paths are resolved against the right type rather than whichever abstract or sibling type .first might return. Falls back to .first for individually-indexed types.

Test plan

  • New unit test in search_response_adapter_builder_spec.rb verifies that all_highlights uses __typename to resolve the concrete type: a hit from the retailers index with __typename: "OnlineStore" correctly resolves a highlight on url (an OnlineStore-specific field absent from the Retailer interface — without the fix, the wrong type would be used and the highlight would be silently dropped)
  • In Add query-time __typename filtering and end-to-end tests for index inheritance #1150, I plan to add an all_highlights acceptance test to search_spec.rb for shared-index types that would fail without the search_response_adapter_builder change made here. That acceptance test requires additions to the stock schema types and remaining index inheritance support that I didn't want to cloud this more focused PR step.

Changes indexed_document_types_by_index_definition_name to accumulate
all indexed document types per index into a Set (was: store only the
first type seen via ||=). This is necessary for correctness with index
inheritance, where multiple concrete types share the same index and all
need to be visible to callers like non_subtypes_in_shared_index.

Renames document_type_stored_in → document_types_stored_in to return
the full Set. Updates the two callers:

- graphql_adapter_builder: .first is safe — this branch is only reached
  for individually-indexed types, which always have exactly one type per
  index (no __typename in the document means no shared index).
- search_response_adapter_builder: use __typename from the document to
  resolve the concrete type directly when present; shared-index types
  carry __typename so field paths in all_highlights resolve to the right
  type. Falls back to .first for individually-indexed types.

Generated with Claude Code
Required by non_subtypes_in_shared_index (on the index inheritance branch),
which needs to enumerate all types sharing an index when deciding whether a
__typename filter is needed on abstract type queries.

Generated with Claude Code
Copy link
Copy Markdown
Collaborator

@myronmarston myronmarston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for spinning this off!

Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb Outdated
Comment thread elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb
- Make indexed_document_types_by_index_definition_name private; public
  callers should use document_types_stored_in instead
- Add unit test for multi-type index inheritance case
- Add DistributionChannel type hierarchy to test schema to support
  acceptance test for __typename-aware all_highlights resolution
- Add acceptance test proving all_highlights resolves against the
  concrete type for documents in a shared-index hierarchy
- Update hidden_types_spec to account for new types
- Add distribution_channels and physical_stores index definitions to
  config settings

Generated with Claude Code
…es_by_index_definition_name

Generated with Claude Code
Copy link
Copy Markdown
Collaborator

@myronmarston myronmarston left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread elasticgraph-graphql/spec/acceptance/search_spec.rb
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema.rb Outdated
Comment thread elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema_spec.rb
@marcdaniels-toast
Copy link
Copy Markdown
Contributor Author

marcdaniels-toast commented Apr 30, 2026

@myronmarston I pushed one more commit that improves the document_types_stored_in docs. And I confirmed it looks good with site:preview_docs:elasticgraph-graphql:
image

@myronmarston myronmarston merged commit 5db050e into block:main Apr 30, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants