Skip to content

fix: improve ast rewriter field provenance#1587

Merged
devsergiy merged 11 commits into
masterfrom
sergiy/router-152-fix-override-of-response-fields-with-a-skipped-fields
Jul 17, 2026
Merged

fix: improve ast rewriter field provenance#1587
devsergiy merged 11 commits into
masterfrom
sergiy/router-152-fix-override-of-response-fields-with-a-skipped-fields

Conversation

@devsergiy

Copy link
Copy Markdown
Member

@coderabbitai summary

Checklist

  • I have discussed my proposed changes in an issue and have received approval to proceed.
  • I have followed the coding standards of the project.
  • Tests or benchmarks have been added or updated.

Open Source AI Manifesto

This project follows the principles of the Open Source AI Manifesto. Please ensure your contribution aligns with its principles.

@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

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: 2be88c8b-9ac6-4f54-92bc-3c64dbd5b91d

📥 Commits

Reviewing files that changed from the base of the PR and between ea669cd and e191494.

📒 Files selected for processing (2)
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go
  • v2/pkg/engine/plan/visitor.go
🚧 Files skipped from review as they are similar to previous changes (2)
  • v2/pkg/engine/plan/visitor.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go

📝 Walkthrough

Walkthrough

The abstract selection rewriter now records field provenance through AST copy and merge hooks, composes exact reference mappings during rewrites, preserves copied __typename provenance, and updates skip propagation from origin mappings. Unit and federation tests cover duplicate fields, aliases, unions, interfaces, and @requires.

Changes

Abstract rewriter provenance

Layer / File(s) Summary
Provenance design contract
docs/superpowers/...
Adds the implementation plan and design specification for copy/merge provenance, mapping composition, typename handling, skip propagation, and verification.
AST copy and merge observation hooks
v2/pkg/ast/ast.go, v2/pkg/ast/ast_field.go, v2/pkg/ast/ast_field_hooks_test.go
Adds optional Document hooks for copied and merged fields, clears them during reset, invokes them from AST operations, and tests their lifecycle and arguments.
Rewrite-time provenance composition
v2/pkg/engine/plan/abstract_selection_rewriter*.go
Records rewrite copy and merge events, builds changedFieldRefs and fieldRefOrigins, replaces path-based collection, and preserves original __typename selections when copied.
Origin-based skip propagation and regression coverage
v2/pkg/engine/plan/node_selection_visitor.go, v2/pkg/engine/plan/abstract_selection_rewriter_changed_refs_test.go, v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go, v2/pkg/engine/plan/visitor.go
Uses field origins to update skipped references and adds coverage for abstract duplicates, aliases, typename handling, federation keys, and @requires.

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

Sequence Diagram(s)

sequenceDiagram
  participant GraphQLDataSource
  participant nodeSelectionVisitor
  participant RewriteFieldSelection
  participant ast.Document
  participant buildRefMappings
  GraphQLDataSource->>nodeSelectionVisitor: process abstract field selection
  nodeSelectionVisitor->>RewriteFieldSelection: rewrite selection
  RewriteFieldSelection->>ast.Document: record copies and merges
  RewriteFieldSelection->>buildRefMappings: compose provenance logs
  buildRefMappings-->>RewriteFieldSelection: return origin mappings
  RewriteFieldSelection-->>nodeSelectionVisitor: return RewriteResult
  nodeSelectionVisitor->>nodeSelectionVisitor: update skip field refs from origins
  nodeSelectionVisitor-->>GraphQLDataSource: produce rewritten plan
Loading
🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 inconclusive)

Check name Status Explanation Resolution
Description check ❓ Inconclusive The description is mostly boilerplate and checklist text, so it does not meaningfully describe the changeset. Replace the boilerplate with a short summary of the implementation changes, impacted areas, and testing performed.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately summarizes the main change: improving ast rewriter field provenance.
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 sergiy/router-152-fix-override-of-response-fields-with-a-skipped-fields

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ast-grep (0.44.1)
v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go

ast-grep timed out on this file


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

@devsergiy
devsergiy force-pushed the sergiy/router-152-fix-override-of-response-fields-with-a-skipped-fields branch from e5db0f1 to 322e240 Compare July 16, 2026 11:50
@devsergiy
devsergiy marked this pull request as ready for review July 17, 2026 08:37
@devsergiy
devsergiy requested a review from a team as a code owner July 17, 2026 08:37
@devsergiy devsergiy changed the title draft: fix losing response field refs due to skipped refs fix: fix losing response fields due to skipped field refs Jul 17, 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

🧹 Nitpick comments (1)
v2/pkg/ast/ast_field_hooks_test.go (1)

11-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover recursive copy observation.

v2/pkg/ast/ast.go promises one callback for every nested field, child before parent, but this test copies only a leaf. Add a nested selection-set case asserting the complete callback sequence; the rewriter relies on this for nested provenance.

🤖 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/ast/ast_field_hooks_test.go` around lines 11 - 29, Extend
TestDocumentFieldHooks with a nested selection-set document containing child and
parent fields, then copy the parent through CopyField. Record each OnCopyField
invocation and assert callbacks occur once per nested field in
child-before-parent order, including the corresponding source and copied
references. Keep the existing leaf-copy assertions intact.
🤖 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 `@docs/superpowers/plans/2026-07-15-abstract-rewriter-ref-provenance.md`:
- Around line 411-412: Update the Task 4 contract in
docs/superpowers/plans/2026-07-15-abstract-rewriter-ref-provenance.md:411-412 to
distinguish provenance keys that are freshly created from refs already
registered in skipFieldsRefs, preserving the synthesized __typename unskip
behavior for pre-registered refs. Retain the unskip regression test in
docs/superpowers/specs/2026-07-15-abstract-rewriter-ref-provenance-design.md:176-182;
no direct implementation change is required there.

---

Nitpick comments:
In `@v2/pkg/ast/ast_field_hooks_test.go`:
- Around line 11-29: Extend TestDocumentFieldHooks with a nested selection-set
document containing child and parent fields, then copy the parent through
CopyField. Record each OnCopyField invocation and assert callbacks occur once
per nested field in child-before-parent order, including the corresponding
source and copied references. Keep the existing leaf-copy assertions intact.
🪄 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: f7fd39b5-59d9-4f9e-b954-9ef11d486707

📥 Commits

Reviewing files that changed from the base of the PR and between 962ece3 and ea669cd.

📒 Files selected for processing (14)
  • docs/superpowers/plans/2026-07-15-abstract-rewriter-ref-provenance.md
  • docs/superpowers/specs/2026-07-15-abstract-rewriter-ref-provenance-design.md
  • v2/pkg/ast/ast.go
  • v2/pkg/ast/ast_field.go
  • v2/pkg/ast/ast_field_hooks_test.go
  • v2/pkg/engine/datasource/graphql_datasource/graphql_datasource_federation_test.go
  • v2/pkg/engine/plan/abstract_selection_rewriter.go
  • v2/pkg/engine/plan/abstract_selection_rewriter_changed_refs_test.go
  • v2/pkg/engine/plan/abstract_selection_rewriter_helpers.go
  • v2/pkg/engine/plan/abstract_selection_rewriter_info.go
  • v2/pkg/engine/plan/abstract_selection_rewriter_provenance.go
  • v2/pkg/engine/plan/abstract_selection_rewriter_provenance_test.go
  • v2/pkg/engine/plan/node_selection_visitor.go
  • v2/pkg/engine/plan/visitor.go

@devsergiy devsergiy changed the title fix: fix losing response fields due to skipped field refs fix: improve ast rewriter field provenance Jul 17, 2026

@Noroth Noroth 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.

LGTM

@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.

@devsergiy
devsergiy merged commit ee8555b into master Jul 17, 2026
10 checks passed
@devsergiy
devsergiy deleted the sergiy/router-152-fix-override-of-response-fields-with-a-skipped-fields branch July 17, 2026 17:07
devsergiy pushed a commit that referenced this pull request Jul 17, 2026
🤖 I have created a release *beep* *boop*
---


##
[2.13.1](v2.13.0...v2.13.1)
(2026-07-17)


### Bug Fixes

* improve ast rewriter field provenance
([#1587](#1587))
([ee8555b](ee8555b))

---
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