Conversation
This PR adds support of input object fields passed as arguments. It handles nested input objects, recursive types, list of input objects and list-typed arguments. Negative weights on input fields reduce the cost, but clamped to zero for each field. Engine PR: wundergraph/graphql-go-tools#1461
|
Important Review skippedThis PR was authored by the user configured for CodeRabbit reviews. CodeRabbit does not review PRs authored by this user. It's recommended to use a dedicated user account to post CodeRabbit review feedback. ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughGraphQL cost calculation now uses request/resolve variables: the GraphQL handler computes actual cost from Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Comment |
Router image scan passed✅ No security vulnerabilities found in image: |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2716 +/- ##
==========================================
- Coverage 63.24% 60.70% -2.54%
==========================================
Files 251 251
Lines 26767 26767
==========================================
- Hits 16929 16250 -679
- Misses 8459 9139 +680
+ Partials 1379 1378 -1
🚀 New features to boost your workflow:
|
…1-cost-handle-recursion-for-arguments-containing-input-objects
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
router-tests/security/costs_test.go (1)
296-344: Add a variable-backed case for the new input-object coverage.These additions only use inline object literals. The router changes here are about request-supplied input values, so a regression in variable handling would still leave this coverage green. In the cache-hit block, using one parameterized query and varying only
Variableswould also prove theHITbehavior without depending on inline-literal normalization.💡 Minimal pattern
- res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{ - Query: `{ findEmployeesBy(criteria: { department: ENGINEERING }) { id } }`, - }) + res := xEnv.MakeGraphQLRequestOK(testenv.GraphQLRequest{ + Query: `query($criteria: FindEmployeeCriteria!) { findEmployeesBy(criteria: $criteria) { id } }`, + Variables: []byte(`{"criteria":{"department":"ENGINEERING"}}`), + })Also applies to: 915-964
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@router-tests/security/costs_test.go` around lines 296 - 344, Add a variable-backed test case to cover input-object handling via variables rather than inline literals: create a t.Run similar to the existing "input object field cost weight" cases but send the criteria as a GraphQL variable (e.g., query with a $criteria variable and set testenv.GraphQLRequest.Variables to {"criteria": {"department":"ENGINEERING"}} or {"title":"Founder"}), assert the same CostEstimatedHeader and CostActualHeader values, and in the cache-hit block repeat the same parameterized query while varying only the Variables to prove HIT behavior; update the existing test functions that call xEnv.MakeGraphQLRequestOK to use Variables instead of inline criteria.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@router-tests/security/costs_test.go`:
- Around line 946-962: The test is reading the actual-cost header from the wrong
response object (resTitle1) for the 3rd and 4th requests; update the assertions
to read core.CostActualHeader from resDept2 for the 3rd request and from
resTitle2 for the 4th request so each request validates its own actual-cost
header (locate the checks near resDept2, resTitle2, resTitle1 and replace the
mistaken resTitle1 usages).
---
Nitpick comments:
In `@router-tests/security/costs_test.go`:
- Around line 296-344: Add a variable-backed test case to cover input-object
handling via variables rather than inline literals: create a t.Run similar to
the existing "input object field cost weight" cases but send the criteria as a
GraphQL variable (e.g., query with a $criteria variable and set
testenv.GraphQLRequest.Variables to {"criteria": {"department":"ENGINEERING"}}
or {"title":"Founder"}), assert the same CostEstimatedHeader and
CostActualHeader values, and in the cache-hit block repeat the same
parameterized query while varying only the Variables to prove HIT behavior;
update the existing test functions that call xEnv.MakeGraphQLRequestOK to use
Variables instead of inline criteria.
🪄 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: 903f7717-2d92-47f7-a210-f315cb99cfb9
⛔ Files ignored due to path filters (1)
demo/pkg/subgraphs/employees/subgraph/generated/generated.gois excluded by!**/generated/**
📒 Files selected for processing (3)
demo/pkg/subgraphs/employees/subgraph/schema.graphqlsrouter-tests/security/costs_test.gorouter-tests/testenv/testdata/config.json
There was a problem hiding this comment.
🧹 Nitpick comments (1)
demo/pkg/subgraphs/employees/subgraph/schema.graphqls (1)
281-281: Consider documenting why negative field cost is intentional.Line 281 uses
@cost(weight: -3), which is easy to misread as accidental. A short inline comment near this field (or the input type) would help prevent future “cleanup” removals.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@demo/pkg/subgraphs/employees/subgraph/schema.graphqls` at line 281, The field 'title: String `@cost`(weight: -3)' uses a negative cost which can be mistaken for an accidental typo; add a short inline comment or description near the 'title' field (or the input/type that contains it) explaining why a negative `@cost`(weight: -3) is intentional (e.g., compensates for other expensive fields, balances query cost model, or enables specific query patterns) so future maintainers won't remove or "clean up" the negative value; reference the 'title' field and the '@cost' directive when adding this documentation.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@demo/pkg/subgraphs/employees/subgraph/schema.graphqls`:
- Line 281: The field 'title: String `@cost`(weight: -3)' uses a negative cost
which can be mistaken for an accidental typo; add a short inline comment or
description near the 'title' field (or the input/type that contains it)
explaining why a negative `@cost`(weight: -3) is intentional (e.g., compensates
for other expensive fields, balances query cost model, or enables specific query
patterns) so future maintainers won't remove or "clean up" the negative value;
reference the 'title' field and the '@cost' directive when adding this
documentation.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: f49d8099-941d-40c6-9346-583af270b8ad
⛔ Files ignored due to path filters (1)
demo/pkg/subgraphs/employees/subgraph/generated/generated.gois excluded by!**/generated/**
📒 Files selected for processing (3)
demo/pkg/subgraphs/employees/subgraph/schema.graphqlsrouter-tests/security/costs_test.gorouter-tests/testenv/testdata/config.json
🚧 Files skipped from review as they are similar to previous changes (1)
- router-tests/security/costs_test.go
…1-cost-handle-recursion-for-arguments-containing-input-objects
…1-cost-handle-recursion-for-arguments-containing-input-objects
This PR adds support of input object fields passed as arguments. It handles nested input objects, recursive types, list of input objects and list-typed arguments.
Negative weights on input fields reduce the cost,
but clamped to zero for each field.
Engine PR: wundergraph/graphql-go-tools#1461
Summary by CodeRabbit