Skip to content

feat(composition): support dot-path in slicingArguments#2801

Open
ysmolski wants to merge 5 commits intomainfrom
yury/eng-9338-router-support-dot-path-in-slicingarguments
Open

feat(composition): support dot-path in slicingArguments#2801
ysmolski wants to merge 5 commits intomainfrom
yury/eng-9338-router-support-dot-path-in-slicingarguments

Conversation

@ysmolski
Copy link
Copy Markdown
Contributor

@ysmolski ysmolski commented Apr 28, 2026

When the list size comes from an argument nested in an input object,
use a dot-separated path in slicingArguments:

input PaginationInput {  first: Int }
input SearchInput {  pagination: PaginationInput }
type Query {
  search(input: SearchInput!): [Book]  @listSize(slicingArguments: ["input.pagination.first"])
}

This PR contains composition changes for now. Composition passes slices argiments in the the same
fields, but this time it parses and validates the dot-path for each slicingArgument.

One small caveat. We should release this in the composition after the router has support for the same feature.
Otherwise, if a user composes config with dot-path slicingArguments and feeds to the router without support of it, then router will throw the error "400" for queries on fields having requireOneSlicingArgument == true. It is because router will ignore such dot-path fields and validation won't pass.

I will make a note on the documentation about these features requiring specific versions of composition and router.

Summary by CodeRabbit

Release Notes

  • Bug Fixes

    • Enhanced validation error messages for nested paths in the listSize directive, providing clearer feedback for invalid path syntax, missing segments, and type traversal errors.
  • Tests

    • Expanded test coverage for nested path validation scenarios.

Copy link
Copy Markdown

@claude claude Bot left a comment

Choose a reason for hiding this comment

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

Claude Code Review

This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 28, 2026

Walkthrough

This PR extends the @listSize directive with support for nested dot-path slicing arguments. Three error message constructors are added to report malformed paths, missing segments, and non-Input-Object intermediates. Path validation logic is implemented to parse segments, traverse the input type hierarchy, and track resolved chains for default-value validation.

Changes

Nested-Path Slicing Arguments Support

Layer / File(s) Summary
Error Message Definitions
composition/src/errors/errors.ts
Three new error message functions added: listSizeSlicingArgumentMalformedPathErrorMessage, listSizeSlicingArgumentSegmentNotFoundErrorMessage, and listSizeSlicingArgumentSegmentNotInputObjectErrorMessage.
Path Validation Logic
composition/src/v1/normalization/normalization-factory.ts
Path parsing validates dot-separated segments, ensures first segment is a valid argument, traverses nested input types, reports missing or non-Input-Object segments, requires leaf to be Int or Int!, and tracks resolved chains for default-value checks against assumedSize.
Tests and Fixtures
composition/tests/v1/directives/listSize.test.ts
New test suite covers single-level and multi-level paths, mixed flat/nested arguments, non-null intermediates/leaves, unknown/malformed paths, non-Input-Object traversals, and interactions with default values and assumedSize; includes comprehensive nested-path fixtures.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.
Title check ✅ Passed The title accurately summarizes the main change: adding support for dot-path syntax in slicingArguments for nested field access, which aligns with the primary objective and all modified files.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch

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

@ysmolski ysmolski requested a review from jensneuse as a code owner April 28, 2026 09:30
@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 28, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 46.25%. Comparing base (6f43c77) to head (6bf922d).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2801       +/-   ##
===========================================
- Coverage   65.92%   46.25%   -19.68%     
===========================================
  Files         254     1084      +830     
  Lines       26527   145132   +118605     
  Branches        0     9263     +9263     
===========================================
+ Hits        17489    67127    +49638     
- Misses       7639    76223    +68584     
- Partials     1399     1782      +383     
Files with missing lines Coverage Δ
composition/src/errors/errors.ts 81.86% <100.00%> (ø)
...tion/src/v1/normalization/normalization-factory.ts 89.91% <100.00%> (ø)

... and 831 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.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 28, 2026

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

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

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

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 the current code and only fix it if needed.

Inline comments:
In `@composition/src/v1/normalization/normalization-factory.ts`:
- Around line 2665-2670: The code currently uses only the first segment
(firstSegment) when reporting a missing root argument, which loses the full SDL
path; change the error creation to pass the full configured argument path (e.g.,
the original slicing argument string or segments.join(".")/slicingArg) into
listSizeInvalidSlicingArgumentErrorMessage instead of firstSegment so the
diagnostic shows the full path; update the call site where argData is checked
(the block referencing segments, firstSegment, argData, errorMessages, and
listSizeInvalidSlicingArgumentErrorMessage) to supply the full path string and
ensure any helpers expecting just the name are adjusted to accept the dotted
path.
🪄 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: 3479e173-63e7-462f-aee0-ad2ba57ad429

📥 Commits

Reviewing files that changed from the base of the PR and between f5929be and 28c3064.

📒 Files selected for processing (4)
  • composition-go/index.global.js
  • composition/src/errors/errors.ts
  • composition/src/v1/normalization/normalization-factory.ts
  • composition/tests/v1/directives/listSize.test.ts

Comment thread composition/src/v1/normalization/normalization-factory.ts
Base automatically changed from yury/eng-8700-router-support-cost-on-the-arguments-of-directives to main April 29, 2026 11:28
@ysmolski ysmolski requested review from a team, Noroth, SkArchon, devsergiy and endigma as code owners April 29, 2026 11:28
@ysmolski ysmolski force-pushed the yury/eng-9338-router-support-dot-path-in-slicingarguments branch from c9873ed to 6bf922d Compare May 6, 2026 13:49
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Caution

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

⚠️ Outside diff range comments (1)
composition/src/errors/errors.ts (1)

1789-1797: ⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Generalize the non-Int message for nested paths.

With dot-path support, this can now describe a nested input field rather than a top-level argument, so the current "references an argument of type" wording is inaccurate for valid new inputs like input.pagination.first.

Suggested wording
 export function listSizeSlicingArgumentNotIntErrorMessage(
   directiveCoords: DirectiveArgumentCoords,
   argumentName: ArgumentName,
   actualType: TypeName,
 ): string {
   return (
-    ` The "slicingArguments" value "${argumentName}" on "${directiveCoords}" references an argument of type` +
+    ` The "slicingArguments" value "${argumentName}" on "${directiveCoords}" references a value of type` +
     ` "${actualType}", but slicing arguments must be of type "Int" or "Int!".`
   );
 }
🤖 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 `@composition/src/errors/errors.ts` around lines 1789 - 1797, The error string
in listSizeSlicingArgumentNotIntErrorMessage is specific to top-level arguments
("references an argument of type") but must cover nested dot-paths (input
fields) as well; update the returned message to use a generalized phrase like
"references a value of type" or "references an input value of type" so the
function listSizeSlicingArgumentNotIntErrorMessage(directiveCoords,
argumentName, actualType) correctly describes both arguments and nested input
fields when actualType is not Int/Int!.
🧹 Nitpick comments (2)
composition/src/v1/normalization/normalization-factory.ts (1)

2669-2670: Gate dotted slicingArguments on router support.

These paths are now serialized into costs.listSizes unchanged. If composition ships before router support, older routers can ignore them and start rejecting requests for fields that still require a slicing argument. Consider enforcing this with a compatibility check, feature gate, or rollout guard instead of relying on release ordering alone.

Also applies to: 2758-2759

🤖 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 `@composition/src/v1/normalization/normalization-factory.ts` around lines 2669
- 2670, Paths are being unconditionally added to listSizeConfig.slicingArguments
and slicingArgChainByPath (slicingArgPath / slicingArgChainByPath), which causes
costs.listSizes to serialize slicing arguments even when downstream routers may
not support them; add a compatibility gate before pushing/setting these values:
detect router support (e.g., via a feature flag or a runtime check like
routerSupportsSlicingArgs(costs) or enableRouterSlicingArgs) and only call
listSizeConfig.slicingArguments.push(slicingArgPath) and
slicingArgChainByPath.set(slicingArgPath, chain) when the gate returns true;
apply the same guarded change for the identical block around lines where slicing
arguments are added (the other occurrence at the reported range 2758-2759).
composition/tests/v1/directives/listSize.test.ts (1)

655-676: ⚡ Quick win

Add a normalized-SDL assertion for a nested-path happy path.

The new success cases only verify costs.listSizes, so a regression in emitted composition output would still pass. Please mirror the earlier normalization checks with at least one assertion that schemaToSortedNormalizedString(schema) preserves @listSize(slicingArguments: ["input.pagination.first"])—ideally also for the mixed flat+nested case.

🤖 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 `@composition/tests/v1/directives/listSize.test.ts` around lines 655 - 676, Add
assertions that verify the normalized SDL still emits the `@listSize` directive
with the nested slicingArguments: after the existing checks in the "nested-path
slicingArguments tests" (in the tests using subgraphWithDeepNestedSlicingArg and
subgraphWithMixedSlicingArgs / ROUTER_COMPATIBILITY_VERSION_ONE), call
schemaToSortedNormalizedString(schema) on the returned schema and assert the
string contains '@listSize(slicingArguments: ["input.pagination.first"])' for
the deep-nested case and contains the corresponding combined form (e.g.
'@listSize(slicingArguments: ["limit","input.pagination.first"])') for the mixed
case; keep these assertions alongside the existing checks that reference
costs.listSizes.get('Query.search') so the test covers both runtime cost
normalization and the emitted normalized SDL.
🤖 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.

Outside diff comments:
In `@composition/src/errors/errors.ts`:
- Around line 1789-1797: The error string in
listSizeSlicingArgumentNotIntErrorMessage is specific to top-level arguments
("references an argument of type") but must cover nested dot-paths (input
fields) as well; update the returned message to use a generalized phrase like
"references a value of type" or "references an input value of type" so the
function listSizeSlicingArgumentNotIntErrorMessage(directiveCoords,
argumentName, actualType) correctly describes both arguments and nested input
fields when actualType is not Int/Int!.

---

Nitpick comments:
In `@composition/src/v1/normalization/normalization-factory.ts`:
- Around line 2669-2670: Paths are being unconditionally added to
listSizeConfig.slicingArguments and slicingArgChainByPath (slicingArgPath /
slicingArgChainByPath), which causes costs.listSizes to serialize slicing
arguments even when downstream routers may not support them; add a compatibility
gate before pushing/setting these values: detect router support (e.g., via a
feature flag or a runtime check like routerSupportsSlicingArgs(costs) or
enableRouterSlicingArgs) and only call
listSizeConfig.slicingArguments.push(slicingArgPath) and
slicingArgChainByPath.set(slicingArgPath, chain) when the gate returns true;
apply the same guarded change for the identical block around lines where slicing
arguments are added (the other occurrence at the reported range 2758-2759).

In `@composition/tests/v1/directives/listSize.test.ts`:
- Around line 655-676: Add assertions that verify the normalized SDL still emits
the `@listSize` directive with the nested slicingArguments: after the existing
checks in the "nested-path slicingArguments tests" (in the tests using
subgraphWithDeepNestedSlicingArg and subgraphWithMixedSlicingArgs /
ROUTER_COMPATIBILITY_VERSION_ONE), call schemaToSortedNormalizedString(schema)
on the returned schema and assert the string contains
'@listSize(slicingArguments: ["input.pagination.first"])' for the deep-nested
case and contains the corresponding combined form (e.g.
'@listSize(slicingArguments: ["limit","input.pagination.first"])') for the mixed
case; keep these assertions alongside the existing checks that reference
costs.listSizes.get('Query.search') so the test covers both runtime cost
normalization and the emitted normalized SDL.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: af468a49-15fd-4b85-baa3-b5b70aea3fd3

📥 Commits

Reviewing files that changed from the base of the PR and between 28c3064 and 6bf922d.

📒 Files selected for processing (4)
  • composition-go/index.global.js
  • composition/src/errors/errors.ts
  • composition/src/v1/normalization/normalization-factory.ts
  • composition/tests/v1/directives/listSize.test.ts

@ysmolski ysmolski changed the title feat: support dot-path in slicingArguments in composition feat(composition): support dot-path in slicingArguments May 6, 2026
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