Skip to content

Add GraphQL::Schema::Type helpers needed for query-time __typename filtering#1161

Merged
myronmarston merged 3 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/graphql-type-schema-helpers
May 2, 2026
Merged

Add GraphQL::Schema::Type helpers needed for query-time __typename filtering#1161
myronmarston merged 3 commits intoblock:mainfrom
marcdaniels-toast:mdaniels/graphql-type-schema-helpers

Conversation

@marcdaniels-toast
Copy link
Copy Markdown
Contributor

@marcdaniels-toast marcdaniels-toast commented May 1, 2026

This is a minimal companion/pre-requisite PR spun off from #1150 to reduce the size of the changeset for review. It adds methods supporting __typename filter injection when querying mixed-type indexes via index inheritance.

  • source_type: resolves the underlying document type for derived types (e.g. indexed aggregations) so the filter can look up search indexes on the source rather than the aggregation type
  • subtypes: declared in RBS so Steep-checked callers can use it
  • non_subtypes_in_shared_index: identifies concrete types sharing an index with this type that are not subtypes — the presence of any such types is what will trigger __typename filter

Screenshots of new YARD docs:
image
image

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/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema/type_spec.rb Outdated
Comment thread elasticgraph-graphql/lib/elastic_graph/graphql/schema/type.rb Outdated
Comment thread elasticgraph-graphql/spec/unit/elastic_graph/graphql/schema/type_spec.rb Outdated
…ltering

This is a companion/pre-requisite PR to add methods supporting __typename filter injection when querying mixed-type indexes via index inheritance.
  * `source_type`: resolves the underlying document type for derived types (e.g. indexed aggregations) so the filter can look up search indexes on the source rather than the aggregation type
  * `subtypes`: declared in RBS so Steep-checked callers can use it
  * `non_subtypes_in_shared_index`: identifies concrete types sharing an index with this type that are not subtypes — the presence of any such types is what triggers the need for a __typename filter
- `source_type`: restore `&.` safe navigation since `@object_runtime_metadata`
  can be nil for non-object types (scalars, enums); return `nil` instead of
  `self` for non-derived types; update `search_index_definitions` to branch on
  `source_type` truthy rather than `indexed_aggregation?`, and update comment
  to describe the general case with indexed aggregation as a prime example
- `subtypes`: return a `Set` instead of `Array`; inline `subtypes` in
  `non_subtypes_in_shared_index` rather than caching in a local variable
- Tests: use `before(:context)` shared schema in `#source_type` group; add
  scalar and enum nil cases; use `contain_exactly` for precise set assertions;
  consolidate `not_to include` calls; add coverage for `t == self` guard

Generated with Claude Code
- `source_type`: use `defined?(@source_type)` pattern to correctly memoize
  nil return values (||= doesn't memoize nil)
- Rename `non_subtypes_in_shared_index` → `concrete_non_subtypes_in_shared_index`
  to make explicit that abstract types are excluded from the result
- Tests: add a second sibling type so at least one test returns multiple
  elements, making it harder for a partial implementation to pass

Generated with Claude Code
@marcdaniels-toast marcdaniels-toast force-pushed the mdaniels/graphql-type-schema-helpers branch from 9732147 to eac440b Compare May 2, 2026 11:47
@myronmarston myronmarston enabled auto-merge (squash) May 2, 2026 15:06
@myronmarston myronmarston merged commit 770801b into block:main May 2, 2026
19 checks passed
@marcdaniels-toast marcdaniels-toast deleted the mdaniels/graphql-type-schema-helpers branch May 3, 2026 19:49
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