Skip to content

Add AbstractTypeFilter query adapter for index inheritance#1163

Merged
myronmarston merged 4 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/index-inheritance-abstract-type-filter
May 5, 2026
Merged

Add AbstractTypeFilter query adapter for index inheritance#1163
myronmarston merged 4 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/index-inheritance-abstract-type-filter

Conversation

@marcdaniels-toast
Copy link
Copy Markdown
Contributor

This is the next PR spun off of the large one #1150 to reduce the size of the changeset for review. After this there are just two more for Issue #1054: one PR for acceptance tests and stock schema updates; and one PR for documentation updates.

When abstract types share an index with unrelated concrete types via index inheritance, a query for the abstract type would otherwise return documents belonging to those other types. AbstractTypeFilter (added here) is a new query adapter that prevents this by automatically injecting an internal __typename filter scoped to the queried type's concrete subtypes.

Also fixes requested_fields to use unwrap_fully before checking abstract?, which ensures __typename is fetched for abstract types returned via the nodes relay connection field (where the field type is list-wrapped, e.g. [Store!]!).

When abstract types share an index with unrelated concrete types via index
inheritance, a query for the abstract type would otherwise return documents
belonging to those other types. AbstractTypeFilter is a new query adapter
that prevents this by automatically injecting an internal __typename filter
scoped to the queried type's concrete subtypes.

Also fixes requested_fields to use unwrap_fully before checking abstract?,
which ensures __typename is fetched for abstract types returned via the
nodes relay connection field (where the field type is list-wrapped, e.g.
[Store!]!).

End-to-end acceptance tests covering index inheritance query behavior are
coming in a follow-up PR; this branch intentionally keeps coverage to
minimal unit tests to reduce the set of reviewable changes.
- Rename `concrete_non_subtypes_in_shared_index` → `shares_index_with_non_subtypes?` (boolean)
- Add nil optimization: only include nil in `__typename` values when a queried index stores a single type
- Replace `ThirdPartyWholesale` with `Wholesale` sub-interface in the stock schema to enable a test for the nil-omitted case
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb
Comment thread config/schema/widgets.rb
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
…ndex when overridden

Abstract types derive their search index set purely from their concrete subtypes.
This avoids unnecessarily searching a shared index when all concrete subtypes have
overridden it with dedicated indexes.

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.

Well done!

@myronmarston myronmarston merged commit 9c32282 into block:main May 5, 2026
19 checks passed
@marcdaniels-toast marcdaniels-toast deleted the mdaniels/index-inheritance-abstract-type-filter branch May 5, 2026 12:29
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