Skip to content

fix(graphql): use placeholders when grouping on leaf-backed object fields - #1454

Closed
myronmarston wants to merge 1 commit into
myron/assert-missing-aggregationsfrom
myron/gh-1453-followups
Closed

myronmarston wants to merge 1 commit into
myron/assert-missing-aggregationsfrom
myron/gh-1453-followups

Conversation

@myronmarston

@myronmarston myronmarston commented Nov 9, 2026 •

Copy link
Copy Markdown
Collaborator

Why. Make sub-aggregation queries that group on leaf-backed object fields (such as the Apollo entity refs from #1453) as efficient as other scalar groupings. A sub-aggregation nests one level per grouping field. A grouping without a missing value placeholder needs a separate missing aggregation at every level, so the number of aggregations grows exponentially and can exceed the max clause count (#882). #890, #893, #894 and #895 added placeholders to terms aggregations, but leaf-backed object fields had none.

Stacked on #1456, which adds the assertions on missing aggregations that this PR updates.

How. The placeholder stays an attribute of the type. Each leaf index field records its type name, and the GraphQL layer looks up that type's placeholder in runtime metadata.

  • IndexField records type_name.
  • Enum runtime metadata records grouping_missing_value_placeholder, as scalar runtime metadata does. Every enum is now dumped, including enums with no value-level metadata.
  • Runtime metadata keeps every scalar and enum type that an index field references, including types the GraphQL schema omits because only indexing_only fields use them.
  • Schema#grouping_missing_value_placeholder_for reads placeholders from runtime metadata. Type uses it, and the query adapter uses the new Type#grouping_missing_value_placeholders_by_index_leaf_path.

Verification. The entity ref assertion from #1456 changes from a missing aggregation on sponsor_id to none. The Boolean and enum assertions stay the same. Without the enum placeholder, the enum assertion fails.

🤖 Generated with Claude Code

@myronmarston
myronmarston force-pushed the myron/gh-1453-followups branch 3 times, most recently from cd0516b to 622f0e5 Compare November 10, 2026 02:54
@myronmarston
myronmarston changed the base branch from main to myron/assert-missing-aggregations November 10, 2026 03:07
@myronmarston

Copy link
Copy Markdown
Collaborator Author

@myronmarston
myronmarston force-pushed the myron/assert-missing-aggregations branch from 4213d33 to 713d132 Compare November 11, 2026 01:26
@myronmarston
myronmarston force-pushed the myron/gh-1453-followups branch from 622f0e5 to 22ad8f6 Compare November 11, 2026 01:26
…elds

Follow-up to #1453. A sub-aggregation grouping on an object field backed by a leaf index field, such
as an Apollo entity ref, used a separate `missing` aggregation instead of a missing value placeholder.
Each `missing` aggregation doubles the number of aggregations below it.

- Record the `type_name` of each leaf `IndexField` in runtime metadata.
- Record `grouping_missing_value_placeholder` on enum runtime metadata, like scalars already do.
  Every enum is now dumped, so the GraphQL layer can look up the placeholder of any enum.
- Keep the runtime metadata of every scalar and enum type that an index field references, even when
  the GraphQL schema omits the type because only `indexing_only` fields use it.
- `Schema#grouping_missing_value_placeholder_for` reads placeholders from runtime metadata. `Type`
  uses it for its own placeholder and for the new
  `grouping_missing_value_placeholders_by_index_leaf_path`, which the query adapter uses instead of
  scanning index definitions.

Generated with Claude Code
@myronmarston
myronmarston force-pushed the myron/gh-1453-followups branch from 22ad8f6 to 7ea13ff Compare November 11, 2026 02:02
myronmarston added a commit that referenced this pull request Nov 12, 2026
… fields more efficient (#1461)

**Why.** Make sub-aggregation queries that group on leaf-backed object
fields (such as the Apollo entity refs from #1453) as efficient as other
scalar groupings. A grouping without a missing value placeholder needs a
separate `missing` aggregation at every level of a sub-aggregation, so
the number of aggregations grows exponentially and can exceed the max
clause count (#882).

This is an alternative to #1454, which fixes the same bug by recording a
type name on every leaf index field (about 640 lines per
`runtime_metadata.yaml`). This PR records the type name only on the
grouped-by fields of object-typed fields backed by a leaf index field: 6
lines in `artifacts_with_apollo` and 1 in `artifacts`. Stacked on #1456,
which adds the assertions on `missing` aggregations that this PR
updates.

**How.** The schema definition records the type of the backing leaf
index field. The GraphQL layer looks up that type and uses its existing
missing value placeholder, so placeholder resolution
(`$SECURE_RANDOM_VALUE`, enums) stays in `Schema::Type`.

- `GraphQLField` runtime metadata gets an optional
`object_grouping_leaf_type_name`.
- `Field#define_grouped_by_field` sets it when the original field has an
object type and the grouped-by field's `name_in_index` resolves, from
the original field's parent type, to a leaf index field.
- The path lookup from `backing_indexing_field` moves to
`HasIndices#indexing_field_at`, so the grouped-by code can resolve the
grouped-by field's `name_in_index` from the original field's parent
type. `f.backing_indexing_field` can't be used: it resolves from the
derived `GroupedBy` type, which has no indexing fields.
- `Schema::Field#object_grouping_leaf_type` looks up the type (nil when
unset), and the query adapter uses that type's placeholder for the
grouping on a leaf-backed field.

**Verification.** The Apollo entity ref test from #1456 no longer uses a
`missing` aggregation. The leaf-backed query adapter tests, including a
new `Boolean` case with no placeholder, fail without the fix.

🤖 Generated with [Claude Code](https://claude.com/claude-code)
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.

1 participant