Skip to content

feat(router): support fields with arguments and @requires (Cosmo Connect)#2731

Merged
dkorittki merged 9 commits intomainfrom
dominik/eng-9263-utilize-engines-support-for-field-args-on-required-fields-on
Apr 8, 2026
Merged

feat(router): support fields with arguments and @requires (Cosmo Connect)#2731
dkorittki merged 9 commits intomainfrom
dominik/eng-9263-utilize-engines-support-for-field-args-on-required-fields-on

Conversation

@dkorittki
Copy link
Copy Markdown
Contributor

@dkorittki dkorittki commented Apr 2, 2026

TLDR:

  • go.mod update on router to use latest engine, which holds the actual feature
  • added router-tests to test the feature in integration-tests
    • had to update schema of gRPC demo subgraph to test the feature

This PR on the engine adds grpc support for fields with arguments and the @requires directive. Here we reference this engine version, so it's supported by the router as well. Once the engine PR gets merged this PR gets updated to use the latest engine version including that feature. I also added some router-tests. Cosmo docs will be updated seperately.

It's a lot of LOC change but only because it involves code generation. The actual changes are small.

Summary by CodeRabbit

  • New Features

    • Employees can now request project summaries filtered by a tag; responses include the employee’s expertise plus either a list of matching project tags (case-insensitive) or a clear "no tags matched" message.
  • Tests

    • Added integration tests covering both matching-tag and non-matching-tag scenarios to validate the filtered summary behavior.

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.
  • Documentation has been updated on https://github.com/wundergraph/docs-website.
  • I have read the Contributors Guide.

Open Source AI Manifesto

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

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Apr 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8ed48a96-8f7e-43bc-8857-5c32caeae499

📥 Commits

Reviewing files that changed from the base of the PR and between 45bc63a and 6dc5405.

⛔ 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 (2)
  • router-tests/go.mod
  • router/go.mod
✅ Files skipped from review due to trivial changes (2)
  • router/go.mod
  • router-tests/go.mod

Walkthrough

Added a federated Employee.filteredProjectSummary(tag: String!) field with @requires(fields: "expertise"), implemented service RPC RequireEmployeeFilteredProjectSummaryById, added integration tests for argument-driven resolution, and bumped github.com/wundergraph/graphql-go-tools/v2 in router modules.

Changes

Cohort / File(s) Summary
Schema
demo/pkg/subgraphs/projects/src/schema.graphql
Added Employee.filteredProjectSummary(tag: String!): String! @requires(fields: "expertise").
Service implementation
demo/pkg/subgraphs/projects/src/service/service.go
Added RequireEmployeeFilteredProjectSummaryById handler that reads per-request context entries, validates employee IDs, obtains expertise via required fields, filters project tags case-insensitively by tag argument, and returns per-context summary strings.
Integration tests
router-tests/protocol/grpc_subgraph_test.go, router-tests/protocol/router_plugin_test.go
Added tests for filteredProjectSummary(tag: "cloud") and filteredProjectSummary(tag: "nonexistent") asserting matching and non-matching tag outputs.
Module dependencies
router/go.mod, router-tests/go.mod
Bumped github.com/wundergraph/graphql-go-tools/v2 from v2.0.0-rc.267 to v2.0.0-rc.268 in both modules.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 2 | ❌ 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 (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main feature being introduced: support for fields with arguments and @requires directive in the router, which is demonstrated across the schema changes, service implementation, and test additions.

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


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

@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 2, 2026

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-6eb0363c0deeebb5f04452c843a74af133576452

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 2, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.24%. Comparing base (ef1f9cf) to head (1383adc).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2731      +/-   ##
==========================================
- Coverage   63.46%   63.24%   -0.22%     
==========================================
  Files         251      251              
  Lines       26767    26767              
==========================================
- Hits        16987    16929      -58     
- Misses       8416     8459      +43     
- Partials     1364     1379      +15     

see 11 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.

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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@demo/pkg/subgraphs/projects/src/service/service.go`:
- Around line 523-529: The deduplication uses the raw tag as the map key (seen)
while the match uses case-insensitive comparison with tagFilter, which allows
duplicates that differ only by case; normalize the tag before using it as a
dedup key (e.g., use strings.ToLower or strings.EqualFold normalization) so that
seen uses the same case-insensitive form, update references to seen, tag and
matchingTags in the loop where tagFilter is checked to use the normalizedKey for
deduping and still append the original tag to matchingTags when appropriate.

In `@router-tests/go.mod`:
- Line 31: The go.mod currently requires go.opentelemetry.io/otel/sdk at an
older version and has a replace that pins it to v1.28.0; update the direct
require for go.opentelemetry.io/otel/sdk to v1.40.0 (or later) and remove or
update the replace directive so it no longer downgrades the SDK to v1.28.0
(ensure any replace entries referencing go.opentelemetry.io/otel/sdk are deleted
or set to >= v1.40.0); after changes run `go mod tidy` to refresh transitive
deps and verify compatibility with google.golang.org/grpc.
🪄 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: 13d40700-5983-4e83-b949-79509e3b23e3

📥 Commits

Reviewing files that changed from the base of the PR and between fe662bf and a077d1c.

⛔ Files ignored due to path filters (6)
  • demo/pkg/subgraphs/projects/generated/mapping.json is excluded by !**/generated/**
  • demo/pkg/subgraphs/projects/generated/service.pb.go is excluded by !**/*.pb.go, !**/generated/**
  • demo/pkg/subgraphs/projects/generated/service.proto is excluded by !**/generated/**
  • demo/pkg/subgraphs/projects/generated/service_grpc.pb.go is excluded by !**/*.pb.go, !**/generated/**
  • router-tests/go.sum is excluded by !**/*.sum
  • router/go.sum is excluded by !**/*.sum
📒 Files selected for processing (6)
  • demo/pkg/subgraphs/projects/src/schema.graphql
  • demo/pkg/subgraphs/projects/src/service/service.go
  • router-tests/go.mod
  • router-tests/protocol/grpc_subgraph_test.go
  • router-tests/testenv/testdata/configWithGRPC.json
  • router/go.mod

@dkorittki dkorittki changed the title feat(router): support fields with arguments and @requires in Cosmo Connect feat(router): support fields with arguments and @requires (Cosmo Connect) Apr 2, 2026
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.

🧹 Nitpick comments (1)
router-tests/protocol/router_plugin_test.go (1)

513-522: Consider adding a mixed-case tag test to lock behavior.

Since resolver matching is case-insensitive, a case like tag: "CLOUD" would protect this contract from regressions.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router-tests/protocol/router_plugin_test.go` around lines 513 - 522, Add a
new test case next to the existing employee filteredProjectSummary tests that
uses a mixed-case tag to lock case-insensitive matching: create an entry named
like "query employee `@requires` field with argument — mixed-case tag" with query
`{ employee(id: 1) { id filteredProjectSummary(tag: "CLOUD") } }` and expected
JSON `{"data":{"employee":{"id":1,"filteredProjectSummary":"expertise: Backend
Architecture, filtered tags (tag=CLOUD): [cloud]"}}}` so the resolver's
case-insensitive match is asserted (update the test slice where the existing two
cases are defined).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@router-tests/protocol/router_plugin_test.go`:
- Around line 513-522: Add a new test case next to the existing employee
filteredProjectSummary tests that uses a mixed-case tag to lock case-insensitive
matching: create an entry named like "query employee `@requires` field with
argument — mixed-case tag" with query `{ employee(id: 1) { id
filteredProjectSummary(tag: "CLOUD") } }` and expected JSON
`{"data":{"employee":{"id":1,"filteredProjectSummary":"expertise: Backend
Architecture, filtered tags (tag=CLOUD): [cloud]"}}}` so the resolver's
case-insensitive match is asserted (update the test slice where the existing two
cases are defined).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 4dcd88bb-2943-45fc-9261-4ae38f9a90a4

📥 Commits

Reviewing files that changed from the base of the PR and between a077d1c and 45bc63a.

⛔ Files ignored due to path filters (1)
  • router/go.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • router-tests/protocol/router_plugin_test.go
  • router-tests/testenv/testdata/configWithPlugins.json

@dkorittki dkorittki merged commit f90dc88 into main Apr 8, 2026
38 checks passed
@dkorittki dkorittki deleted the dominik/eng-9263-utilize-engines-support-for-field-args-on-required-fields-on branch April 8, 2026 11:11
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.

3 participants