Skip to content

feat(router): router force use of variables and not inline values - #3055

Merged
SkArchon merged 34 commits into
mainfrom
milinda/eng-9586-routerengine-force-use-of-variables
Jul 15, 2026
Merged

feat(router): router force use of variables and not inline values#3055
SkArchon merged 34 commits into
mainfrom
milinda/eng-9586-routerengine-force-use-of-variables

Conversation

@SkArchon

@SkArchon SkArchon commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

This PR adds the capability to block inline arguments. This is useful to increase normalization cache hit rates. The feature is broken down into three modes.

  • Enforcing: Error when inline args are present
  • Non-Enforcing: Don't error but warn log when inline args are present
  • Off: Do Nothing

In addition to this we have two additional options which allow users to either exempt (default) or also validate persisted operations, as well as return extensions (two formats for "Enforcing" and "Non-Enforcing").

This PR depends on wundergraph/graphql-go-tools#1577

Summary by CodeRabbit

  • New Features
    • Added engine.disallow_inline_arguments policy (config/env) to detect inline GraphQL argument values with modes: off, enabled-non-enforcing, enabled-enforcing, including options for persisted operations and optional extensions.inlineArguments.
    • Consistent behavior across HTTP, WebSocket subscriptions, and persisted operations.
  • Bug Fixes
    • Enforcing mode now rejects requests with HTTP 400 using generic GraphQL errors; non-enforcing mode emits warnings (on both cache miss and hit) and preserves behavior across normalization and normalization-cache flows.
  • Tests
    • Added integration coverage for inline-argument detection, warnings/extensions, and persisted-operation behavior.
  • Chores
    • Updated github.com/wundergraph/graphql-go-tools/v2 version.

Checklist

Open Source AI Manifesto

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

@github-actions github-actions Bot added the router label Jul 7, 2026
@github-actions

github-actions Bot commented Jul 7, 2026

Copy link
Copy Markdown

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-c3b94f20b483868e1a0204e28dab23f1023046ca-nonroot

@coderabbitai

coderabbitai Bot commented Jul 7, 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

Walkthrough

This PR adds configurable inline-argument disallowance for GraphQL operations, carries inline-argument findings through normalization and caching, propagates them into HTTP and WebSocket execution paths, and adds integration coverage. It also updates graphql-go-tools/v2 in both modules.

Changes

Disallow Inline Arguments feature

Layer / File(s) Summary
Configuration and schema
router/pkg/config/config.go, router/pkg/config/config.schema.json, router/pkg/config/testdata/config_defaults.json, router/pkg/config/testdata/config_full.json
Adds the DisallowInlineArguments config type, mode enum, schema block, and default/full config fixtures.
Operation processor normalization and caching
router/core/operation_processor.go
Adds inline-argument findings to parsed operations, wires validation into normalization, persists findings in normalization cache entries, restores them on cache hits, and clears validator state when releasing the kit.
HTTP and WebSocket handler integration
router/core/context.go, router/core/graph_server.go, router/core/graphql_handler.go, router/core/graphql_prehandler.go, router/core/websocket.go
Wires config into operation processor creation, stores inline arguments on operation context, copies them into resolve context, and logs them in HTTP and WebSocket flows.
Integration tests and dependency updates
router-tests/operations/disallow_inline_arguments_test.go, router-tests/go.mod, router/go.mod
Adds coverage for enforcing, non-enforcing, persisted-operation, cache-hit, and WebSocket behavior, and updates graphql-go-tools/v2 in both module files.

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

Possibly related PRs

  • wundergraph/cosmo#3041: Modifies router/core/graphql_prehandler.go around parsing and validation before normalization, which overlaps with the inline-argument handling flow.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: disallowing inline argument values in favor of variables.

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

@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)
router/core/websocket.go (1)

970-997: 🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

Inline-argument reporting order diverges from the HTTP prehandler.

Here the logInlineArguments/ReturnInResponseExtensions block runs before NormalizeVariables(), whereas in graphql_prehandler.go the equivalent block runs after NormalizeVariables() succeeds (and only then). If NormalizeVariables() fails on WS, the warning/extension has already been emitted even though the request is aborted — on HTTP the same failure prevents the log/extension from firing at all. This contradicts the explicit "matching the HTTP prehandler" intent in the comments here.

🐛 Proposed fix to match HTTP ordering
 	opContext.normalizationCacheHit = operationKit.parsedOperation.NormalizationCacheHit
 
-	// Non-enforcing mode: warn about any inline argument values, matching the HTTP
-	// prehandler so subscriptions over WebSockets are not silently exempt.
-	logInlineArguments(h.logger, operationKit.parsedOperation)
-
-	// When configured, also surface the inline arguments to the client under
-	// `extensions.inlineArguments`, matching the HTTP prehandler.
-	if h.operationProcessor.parseKitOptions.disallowInlineArguments.ReturnInResponseExtensions {
-		opContext.inlineArguments = inlineArgumentQualifiedNames(operationKit.parsedOperation)
-	}
-
 	// Validate the operation against the schema BEFORE variable extraction, which would
 	// serialize inline literals into JSON variables and let invalid-type literals through.
 	// The error is surfaced later, during validation, so normalization timing stays accurate.
 	_, operationValidationErr := operationKit.ValidateOperation()
 
 	cached, _, err := operationKit.NormalizeVariables()
 	if err != nil {
 		opContext.normalizationTime = time.Since(startNormalization)
 		return nil, nil, err
 	}
 	opContext.variablesNormalizationCacheHit = cached
+
+	// Non-enforcing mode: warn about any inline argument values, matching the HTTP
+	// prehandler so subscriptions over WebSockets are not silently exempt.
+	logInlineArguments(h.logger, operationKit.parsedOperation)
+
+	// When configured, also surface the inline arguments to the client under
+	// `extensions.inlineArguments`, matching the HTTP prehandler.
+	if h.operationProcessor.parseKitOptions.disallowInlineArguments.ReturnInResponseExtensions {
+		opContext.inlineArguments = inlineArgumentQualifiedNames(operationKit.parsedOperation)
+	}
🤖 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 `@router/core/websocket.go` around lines 970 - 997, Move the inline-argument
reporting in the websocket operation flow so it matches the HTTP prehandler
ordering: in `handleOperation` (or the surrounding websocket normalization
path), keep `NormalizeOperation` first, then call `NormalizeVariables()`, and
only after that succeeds run `logInlineArguments` and populate
`opContext.inlineArguments` when `ReturnInResponseExtensions` is enabled. This
ensures the warning and response extension are emitted only for requests that
fully normalize, consistent with `graphql_prehandler.go`.
🧹 Nitpick comments (1)
router/core/graphql_prehandler.go (1)

889-898: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider extracting a shared "report inline arguments" helper.

The same three-line ReturnInResponseExtensions gate plus the logInlineArguments call is duplicated here and in websocket.go (lines 978-987). As shown in the websocket.go review, the two call sites have already drifted in execution order relative to NormalizeVariables. A single shared helper (e.g. reportInlineArguments(logger, parsedOperation, disallowInlineArguments) []string) called at the same normalization stage in both places would eliminate this duplication and prevent future divergence.

Also applies to: 1428-1459

🤖 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 `@router/core/graphql_prehandler.go` around lines 889 - 898, The
inline-arguments reporting logic is duplicated and has already drifted between
GraphQL prehandler and websocket handling. Extract a shared helper around
logInlineArguments and the ReturnInResponseExtensions gate, such as
reportInlineArguments(logger, parsedOperation, disallowInlineArguments), and
call it from both graphql_prehandler.go and websocket.go at the same
NormalizeVariables stage so both paths stay aligned and return the inline
argument names consistently.
🤖 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 `@router/pkg/config/config.schema.json`:
- Around line 3662-3666: The enforce_http_status_code schema in
config.schema.json currently allows any integer, which can let enforce-mode
rejections use non-error responses like 200. Tighten the schema for
enforce_http_status_code by adding a valid HTTP rejection range constraint (for
example, minimum 400 and maximum 599) while keeping the existing default and
description intact so misconfiguration is prevented.

---

Outside diff comments:
In `@router/core/websocket.go`:
- Around line 970-997: Move the inline-argument reporting in the websocket
operation flow so it matches the HTTP prehandler ordering: in `handleOperation`
(or the surrounding websocket normalization path), keep `NormalizeOperation`
first, then call `NormalizeVariables()`, and only after that succeeds run
`logInlineArguments` and populate `opContext.inlineArguments` when
`ReturnInResponseExtensions` is enabled. This ensures the warning and response
extension are emitted only for requests that fully normalize, consistent with
`graphql_prehandler.go`.

---

Nitpick comments:
In `@router/core/graphql_prehandler.go`:
- Around line 889-898: The inline-arguments reporting logic is duplicated and
has already drifted between GraphQL prehandler and websocket handling. Extract a
shared helper around logInlineArguments and the ReturnInResponseExtensions gate,
such as reportInlineArguments(logger, parsedOperation, disallowInlineArguments),
and call it from both graphql_prehandler.go and websocket.go at the same
NormalizeVariables stage so both paths stay aligned and return the inline
argument names consistently.
🪄 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: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df4508ff-fc1a-492c-aab7-bf24c627b117

📥 Commits

Reviewing files that changed from the base of the PR and between 38aad29 and 354d8df.

⛔ Files ignored due to path filters (2)
  • router-tests/go.sum is excluded by !**/*.sum
  • router/go.sum is excluded by !**/*.sum
📒 Files selected for processing (13)
  • router-tests/go.mod
  • router-tests/operations/disallow_inline_arguments_test.go
  • router/core/context.go
  • router/core/graph_server.go
  • router/core/graphql_handler.go
  • router/core/graphql_prehandler.go
  • router/core/operation_processor.go
  • router/core/websocket.go
  • router/go.mod
  • router/pkg/config/config.go
  • router/pkg/config/config.schema.json
  • router/pkg/config/testdata/config_defaults.json
  • router/pkg/config/testdata/config_full.json

Comment thread router/pkg/config/config.schema.json
@SkArchon SkArchon changed the title Milinda/eng 9586 routerengine force use of variables feat(router): router force use of variables and not inline values Jul 7, 2026
@codecov

codecov Bot commented Jul 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 61.97%. Comparing base (3c15243) to head (1fbd473).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3055      +/-   ##
==========================================
- Coverage   71.04%   61.97%   -9.07%     
==========================================
  Files         335      261      -74     
  Lines       49334    30714   -18620     
  Branches     6033        0    -6033     
==========================================
- Hits        35047    19036   -16011     
+ Misses      14261    10169    -4092     
- Partials       26     1509    +1483     
Files with missing lines Coverage Δ
router/core/context.go 74.92% <ø> (ø)
router/core/graph_server.go 85.52% <100.00%> (ø)
router/core/graphql_handler.go 62.19% <100.00%> (ø)
router/core/graphql_prehandler.go 87.31% <100.00%> (ø)
router/core/operation_processor.go 86.69% <100.00%> (ø)
router/core/websocket.go 77.64% <100.00%> (ø)
router/pkg/config/config.go 83.00% <100.00%> (ø)

... and 589 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mintlify

mintlify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
wundergraphinc 🟢 Ready View Preview Jul 7, 2026, 12:29 PM

💡 Tip: Enable Workflows to automatically generate PRs for you.

@endigma
endigma self-requested a review July 7, 2026 13:57
Comment thread router/pkg/config/config.go Outdated
Comment thread router/core/operation_processor.go Outdated
@coderabbitai

coderabbitai Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

An error occurred during the review process. Please try again later.

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

Walkthrough

This PR adds configurable inline-argument disallowance for GraphQL operations, carries inline-argument findings through normalization and caching, propagates them into HTTP and WebSocket execution paths, and adds integration coverage. It also updates graphql-go-tools/v2 in both modules.

Changes

Disallow Inline Arguments feature

Layer / File(s) Summary
Configuration and schema
router/pkg/config/config.go, router/pkg/config/config.schema.json, router/pkg/config/testdata/config_defaults.json, router/pkg/config/testdata/config_full.json
Adds the DisallowInlineArguments config type, mode enum, schema block, and default/full config fixtures.
Operation processor normalization and caching
router/core/operation_processor.go
Adds inline-argument findings to parsed operations, wires validation into normalization, persists findings in normalization cache entries, restores them on cache hits, and clears validator state when releasing the kit.
HTTP and WebSocket handler integration
router/core/context.go, router/core/graph_server.go, router/core/graphql_handler.go, router/core/graphql_prehandler.go, router/core/websocket.go
Wires config into operation processor creation, stores inline arguments on operation context, copies them into resolve context, and logs them in HTTP and WebSocket flows.
Integration tests and dependency updates
router-tests/operations/disallow_inline_arguments_test.go, router-tests/go.mod, router/go.mod
Adds coverage for enforcing, non-enforcing, persisted-operation, cache-hit, and WebSocket behavior, and updates graphql-go-tools/v2 in both module files.

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

Possibly related PRs

  • wundergraph/cosmo#3041: Modifies router/core/graphql_prehandler.go around parsing and validation before normalization, which overlaps with the inline-argument handling flow.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: disallowing inline argument values in favor of variables.

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

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

@SkArchon
SkArchon merged commit 85f893c into main Jul 15, 2026
39 checks passed
@SkArchon
SkArchon deleted the milinda/eng-9586-routerengine-force-use-of-variables branch July 15, 2026 13:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants