Skip to content

feat: improve abstract field validation - #1588

Merged
endigma merged 9 commits into
masterfrom
jesse/router-243-add-validation-for-abstract-types
Jul 17, 2026
Merged

feat: improve abstract field validation#1588
endigma merged 9 commits into
masterfrom
jesse/router-243-add-validation-for-abstract-types

Conversation

@endigma

@endigma endigma commented Jul 14, 2026

Copy link
Copy Markdown
Member

Also incorporates a fix to one of the execution test runners, we cannot run t.Parallel() inside because the whole thing is slightly flawed where the wrong t is captured for must…(t, …) type invocations on fields of the TC struct.

This is normally not an issue as the must… helpers are usually just ceremony for dropping the error value, but when we might actually expect them to fail they will panic by calling require.XXX(t, …) with the parent t instead of the subtest t.

This can be resolved by in these cases evaluating it and all of its arguments within the subtest closure func(t) { … } but then the tparallel linter complains about missing parallel, which cannot be fixed because the inner function also tried to call it.

The proper way to fix this would be to have dataSources etc fields on the TC be evaluated with subtest t via like dataSources: func (t testing.T) []*DataSource instead of directly providing it, but this would be a very intrusive change.

@endigma
endigma requested a review from a team as a code owner July 14, 2026 17:09
@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: ee3ade01-c8e0-4770-8e11-e4929ccff9a5

📥 Commits

Reviewing files that changed from the base of the PR and between 37b5eb1 and 9fd2746.

📒 Files selected for processing (1)
  • execution/engine/execution_engine_cost_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
  • execution/engine/execution_engine_cost_test.go

📝 Walkthrough

Walkthrough

The execution planner now requests __typename for interface and union selections. Abstract runtime values are validated against accessible and inaccessible members, with missing or invalid values producing errors, null propagation, and updated cost-test expectations.

Changes

Abstract type validation

Layer / File(s) Summary
Runtime typename planning
v2/pkg/engine/datasource/graphql_datasource/*, execution/engine/execution_engine_test.go, execution/engine/testdata/*
Interface and union selections now request __typename; federation, execution, and trace expectations include the injected field.
Abstract value resolution
v2/pkg/engine/plan/visitor.go, v2/pkg/engine/resolve/*, execution/engine/execution_engine_cost_test.go
Inaccessible members are retained separately, while missing or inaccessible runtime typenames produce validation errors and null propagation; affected actual-cost expectations are updated.
End-to-end validation coverage
execution/engine/abstract_type_validation_test.go, execution/engine/execution_engine_helpers_test.go
Table-driven tests cover interfaces, unions, lists, fragments, inaccessible members, request validation, and value-completion responses.
Execution and cost regression expectations
execution/engine/execution_engine_test.go, execution/engine/execution_engine_cost_test.go, execution/engine/execution_engine_helpers_test.go
Existing execution fixtures and cost assertions reflect injected typenames, concrete abstract results, and rejected values receiving no actual cost.

Estimated code review effort: 4 (Complex) | ~45 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Client
  participant Planner
  participant Subgraph
  participant Resolvable
  Client->>Planner: submit abstract field selection
  Planner->>Subgraph: request fields with __typename
  Subgraph-->>Resolvable: return abstract value
  Resolvable->>Resolvable: validate runtime typename
  Resolvable-->>Client: return data, nulls, or INVALID_GRAPHQL errors
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: improved abstract field validation.
Description check ✅ Passed The description matches the test-runner fix included in the pull request and is on-topic.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch jesse/router-243-add-validation-for-abstract-types

Comment @coderabbitai help to get the list of available commands.

@endigma endigma changed the title feat(engine): always request and enforce __typename for abstract values feat: improve abstract field validation Jul 14, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
v2/pkg/engine/plan/visitor.go (1)

811-848: 🗄️ Data Integrity & Integration | 🟡 Minor | ⚡ Quick win

Handle abstract types with no accessible members. When every interface implementer or union member is @inaccessible, PossibleTypes is empty, so isAbstract() returns false and the __typename validation path is skipped entirely. Treat that zero-accessible-members case as abstract too, and add a regression test.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@v2/pkg/engine/plan/visitor.go` around lines 811 - 848, Update the
abstract-type construction and isAbstract logic so interfaces or unions with
only inaccessible implementers/members are still classified as abstract when
PossibleTypes is empty but InaccessibleTypes is populated. Ensure __typename
validation runs for this zero-accessible-members case, and add a regression test
covering an interface or union whose every member is `@inaccessible`.
🧹 Nitpick comments (1)
execution/engine/execution_engine_cost_test.go (1)

295-332: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add expectedResponse assertion for the rejection behavior this test targets.

This test verifies cost (expectedActualCost: 0) but never asserts that the response actually contains the INVALID_GRAPHQL rejection/null for the missing __typename, unlike the analogous tests at Lines 782-794 and 7505-7513 in this same file. As written, a cost-side regression that still yields 0 for an unrelated reason (e.antml:cite the field simply carrying no weight) would pass this test undetected.

♻️ Suggested addition
 expectedEstimatedCost: intPtr(13), // Query.hero(13)
 // the abstract hero value is rejected and nulled, so nothing is billed
 expectedActualCost: intPtr(0),
+expectedResponse: `{"errors":[{"message":"Subgraph 'id' returned an invalid value for __typename field.","path":["hero"],"extensions":{"code":"INVALID_GRAPHQL"}}],"data":{"hero":null}}`,

(Adjust the exact message/path to match actual engine output.)

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@execution/engine/execution_engine_cost_test.go` around lines 295 - 332, Add
an expectedResponse assertion to the “single abstract field without __typename
is rejected and bills nothing” test, verifying that hero is null and the
response includes the INVALID_GRAPHQL rejection with the correct message/path
for the missing __typename. Match the established response shape and exact
engine output used by the analogous tests, while preserving the existing cost
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@execution/engine/abstract_type_validation_test.go`:
- Around line 13-14: Suppress the tparallel lint warning for the affected
subtests in TestAbstractTypeValidation, including the cases around the
additional reported range. Place a targeted tparallel nolint directive on the
relevant t.Run calls or closures, and do not add another t.Parallel() call
because runWithoutError/runExecutionTest already invokes it.

---

Outside diff comments:
In `@v2/pkg/engine/plan/visitor.go`:
- Around line 811-848: Update the abstract-type construction and isAbstract
logic so interfaces or unions with only inaccessible implementers/members are
still classified as abstract when PossibleTypes is empty but InaccessibleTypes
is populated. Ensure __typename validation runs for this zero-accessible-members
case, and add a regression test covering an interface or union whose every
member is `@inaccessible`.

---

Nitpick comments:
In `@execution/engine/execution_engine_cost_test.go`:
- Around line 295-332: Add an expectedResponse assertion to the “single abstract
field without __typename is rejected and bills nothing” test, verifying that
hero is null and the response includes the INVALID_GRAPHQL rejection with the
correct message/path for the missing __typename. Match the established response
shape and exact engine output used by the analogous tests, while preserving the
existing cost assertions.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 0ccfe3b3-5d11-425f-a42f-31b8850be6e6

📥 Commits

Reviewing files that changed from the base of the PR and between f79b189 and 39fb2f9.

📒 Files selected for processing (12)
  • execution/engine/abstract_type_validation_test.go
  • execution/engine/execution_engine_cost_test.go
  • execution/engine/execution_engine_helpers_test.go
  • execution/engine/execution_engine_test.go
  • execution/engine/testdata/complex_nesting_query_with_art.json
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_interface_provides_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_test.go
  • v2/pkg/engine/plan/visitor.go
  • v2/pkg/engine/resolve/node_object.go
  • v2/pkg/engine/resolve/resolvable.go

Comment thread execution/engine/abstract_type_validation_test.go
@endigma
endigma force-pushed the jesse/router-243-add-validation-for-abstract-types branch from 29e94e5 to c8b4bce Compare July 15, 2026 18:40

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@execution/engine/abstract_type_validation_test.go`:
- Around line 247-310: Move the test client construction involving
testNetHttpClient and roundTripperTestCase into the t.Run callback so it
receives the subtest’s t, ensuring request-body assertions target the correct
subtest. Update the runner or ExecutionEngineTestCase setup around mustFactory
and mustGraphqlDataSourceConfigurationWithName while preserving the existing
test configuration and expectations.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 84049401-2a11-4536-980c-7bed803fb820

📥 Commits

Reviewing files that changed from the base of the PR and between 39fb2f9 and 29e94e5.

📒 Files selected for processing (1)
  • execution/engine/abstract_type_validation_test.go

Comment thread execution/engine/abstract_type_validation_test.go Outdated
endigma added 2 commits July 16, 2026 15:34

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Claude Code Review

Claude Code Review is paused for this repository. To reconnect it, an admin of this repository's GitHub organization (or the account owner, for personal repositories) who can also manage your Claude organization's Code Review settings needs to re-link GitHub in Code Review settings. This is a one-time step.

Tip: disable this comment in your organization's Code Review settings.

Comment thread execution/engine/execution_engine_cost_test.go
Comment thread execution/engine/execution_engine_cost_test.go Outdated
Comment thread execution/engine/execution_engine_helpers_test.go
Comment thread execution/engine/execution_engine_test.go
@endigma
endigma force-pushed the jesse/router-243-add-validation-for-abstract-types branch from 76f190f to 9fd2746 Compare July 17, 2026 10:44
@ysmolski

Copy link
Copy Markdown
Contributor

LGTM

@endigma
endigma merged commit d6cceac into master Jul 17, 2026
10 checks passed
@endigma
endigma deleted the jesse/router-243-add-validation-for-abstract-types branch July 17, 2026 10:55
endigma pushed a commit that referenced this pull request Jul 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.13.0](v2.12.1...v2.13.0)
(2026-07-17)


### Features

* improve abstract field validation
([#1588](#1588))
([d6cceac](d6cceac))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

Co-authored-by: wundergraph-bot[bot] <285992168+wundergraph-bot[bot]@users.noreply.github.com>
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