Skip to content

feat(router): add support for composite types in requires fields#2689

Merged
Noroth merged 13 commits intomainfrom
ludwig/eng-9226-add-composite-type-support-in-cosmo
Mar 27, 2026
Merged

feat(router): add support for composite types in requires fields#2689
Noroth merged 13 commits intomainfrom
ludwig/eng-9226-add-composite-type-support-in-cosmo

Conversation

@Noroth
Copy link
Copy Markdown
Contributor

@Noroth Noroth commented Mar 25, 2026

This PR adds support for using composite types in @requires in the router

Summary by CodeRabbit

Release Notes

  • New Features

    • Expanded employee profiles to include primary work items (technical or management variants)
    • Added work review history with approval and rejection records
    • Introduced work setup details with priority and configuration tracking
    • Work items now include handler assignments and detailed metrics/specifications
  • Tests

    • Added comprehensive test coverage for composite work item queries and resolution patterns

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 Mar 25, 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: b695dc54-c0c0-45fe-82dd-730c9648d715

📥 Commits

Reviewing files that changed from the base of the PR and between 6736fb6 and 1f8b16e.

📒 Files selected for processing (5)
  • router-tests/operations/testdata/introspection/base-graph-schema.json
  • router-tests/testenv/testdata/config.json
  • router-tests/testenv/testdata/configWithEdfs.json
  • router-tests/testenv/testdata/configWithGRPC.json
  • router-tests/testenv/testdata/configWithPlugins.json
🚧 Files skipped from review as they are similar to previous changes (1)
  • router-tests/operations/testdata/introspection/base-graph-schema.json

Walkthrough

This PR extends a GraphQL federation demo by introducing work-related type definitions and fields for employees. It adds EmployeeWorkItem interface with concrete implementations (TechnicalWorkItem, ManagementWorkItem), WorkReviewResult union type with approval/rejection variants, and WorkSetup composite types across employees and projects subgraphs, along with new gRPC @requires resolution handlers and corresponding test coverage.

Changes

Cohort / File(s) Summary
Employees Subgraph – Data & Models
demo/pkg/subgraphs/employees/subgraph/employees.go, demo/pkg/subgraphs/employees/subgraph/model/models_gen.go
Added work-related seed data for first two employees; introduced new Go types (ManagementWorkItem, TechnicalWorkItem, WorkApproval, WorkRejection, WorkSetup, etc.) implementing EmployeeWorkItem and WorkReviewResult interfaces.
Employees Subgraph – Resolvers & Schema
demo/pkg/subgraphs/employees/subgraph/entity.resolvers.go, demo/pkg/subgraphs/employees/subgraph/schema.graphqls, demo/pkg/subgraphs/employees/subgraph/schema.resolvers.go
Updated entity and schema resolvers to populate PrimaryWorkItem, LastWorkReview, and WorkSetup fields; extended GraphQL schema with new interface, union, and object type definitions for work items and reviews.
Projects Subgraph – Federation & Service
demo/pkg/subgraphs/projects/src/schema.graphql, demo/pkg/subgraphs/projects/src/service/service.go
Extended federated Employee type with @external work-related fields and computed @requires string fields; added six new ProjectsService RPC handlers implementing type-specific resolution logic for composite work item, review, and setup data.
Test Coverage – Protocol & Operations
router-tests/protocol/grpc_subgraph_test.go, router-tests/protocol/router_plugin_test.go, router-tests/operations/testdata/introspection/base-graph-schema.json, router-tests/operations/testdata/introspection/feature-graph-schema.json
Added 14+ test cases validating @requires resolution across abstract interfaces, unions, and concrete nesting patterns; updated introspection schema snapshots to reflect new work-item type hierarchy.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 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: adding support for composite types in @requires fields, which is evident from all file changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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

This comment has been minimized.

@github-actions

This comment has been minimized.

@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 25, 2026

Router image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-b437cf6415349aea625b8128dc28fc4a0acfefad

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 25, 2026

Codecov Report

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

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #2689       +/-   ##
===========================================
+ Coverage   45.48%   63.10%   +17.62%     
===========================================
  Files        1028      245      -783     
  Lines      138352    26273   -112079     
  Branches     8594        0     -8594     
===========================================
- Hits        62925    16580    -46345     
+ Misses      73710     8352    -65358     
+ Partials     1717     1341      -376     

see 798 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: 6

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

398-401: Verify if PrintQueryPlans should remain enabled.

cfg.Debug.PrintQueryPlans = true was added along with the test cases. This is useful for debugging but may add noise to test output in CI. Consider whether this should remain enabled or be removed before merge.

If debug output is not needed in CI:
 		testenv.Run(t, &testenv.Config{
 			RouterConfigJSONTemplate: testenv.ConfigWithGRPCJSONTemplate,
-			ModifyEngineExecutionConfiguration: func(cfg *config.EngineExecutionConfiguration) {
-				cfg.Debug.PrintQueryPlans = true
-			},
 			EnableGRPC: true,
 		},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@router-tests/protocol/grpc_subgraph_test.go` around lines 398 - 401, The test
enables verbose plan printing by setting cfg.Debug.PrintQueryPlans = true inside
ModifyEngineExecutionConfiguration which may clutter CI logs; change this to
false (or remove the assignment) so tests run with PrintQueryPlans disabled, or
gate it behind a CI-debug flag (e.g., check an env var in
ModifyEngineExecutionConfiguration and only set cfg.Debug.PrintQueryPlans = true
when that flag is present) to preserve the option for local debugging.
🤖 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/schema.graphql`:
- Line 270: The WorkReviewResult union definition is missing the `@shareable`
directive; update the union declaration for WorkReviewResult (which composes
WorkApproval and WorkRejection) to include `@shareable` so it matches the
employees subgraph and allows proper federation composition. Locate the union
named WorkReviewResult and append the `@shareable` directive to its declaration.

In `@demo/pkg/subgraphs/projects/src/service/service.go`:
- Around line 624-648: In RequireEmployeeWorkItemHandlerInfoById, guard against
a nil primary work item and nil instance before doing the type switch: after
retrieving item := ctx.GetFields().GetPrimaryWorkItem(), check if item == nil ||
item.GetInstance() == nil and set info = "Unknown handler" (or equivalent) and
skip the type switch; otherwise perform the existing switch on
item.GetInstance() to populate info and append the
service.RequireEmployeeWorkItemHandlerInfoByIdResult. Ensure you reference the
same variables (ctx, item, info) and return the response as before.
- Around line 571-595: In RequireEmployeeReviewReportById, guard against nil
lastWorkReview before calling review.GetValue(): check
ctx.GetFields().GetLastWorkReview() for nil (and that review.GetValue() is
non-nil) and handle that case by producing a default "Unknown review" (or
similar) report instead of dereferencing; update the switch on review.GetValue()
to only run when non-nil and fall back to the default report when review is nil
or value is nil, keeping the existing result append logic.
- Around line 597-622: In RequireEmployeeWorkSetupSummaryById, guard against a
nil work setup returned by ctx.GetFields().GetWorkSetup(): check that setup !=
nil before calling setup.GetPrimaryItem() and setup.GetPriority(); if setup is
nil, use a safe default (e.g., itemSummary "Unknown work item" and priority from
a default or empty string) or append a result that indicates missing work setup,
then continue building results to avoid a panic when accessing
setup.GetPriority().
- Around line 545-569: The handler RequireEmployeeWorkItemInfoById may
dereference a nil primary work item; before calling item.GetInstance() inside
the loop over req.GetContext(), check whether ctx.GetFields()==nil or item :=
ctx.GetFields().GetPrimaryWorkItem(); item==nil and handle that case (e.g. set
summary = "No work item" or skip) so you avoid a nil pointer panic; update the
switch to only run when item is non-nil and construct the
service.RequireEmployeeWorkItemInfoByIdResult accordingly.
- Around line 680-713: The handler RequireEmployeeDeepWorkItemInfoById risks nil
derefs when accessing nested fields; defend by checking for nil before using
item := ctx.GetFields().GetPrimaryWorkItem() (skip or set "Unknown deep item" if
nil), then when handling the technical branch validate handler :=
v.TechnicalWorkItem.GetHandler() is non-nil before calling
handler.GetAssignedItem(), and validate assignedItem is non-nil before switching
on assignedItem.GetInstance(); on any nil, set a clear fallback info string
(e.g., "Unknown deep item" or "TechnicalHandler->Unknown") and continue,
updating the branches that reference av (ManagementWorkItem / TechnicalWorkItem)
only after confirming av is non-nil as well.

---

Nitpick comments:
In `@router-tests/protocol/grpc_subgraph_test.go`:
- Around line 398-401: The test enables verbose plan printing by setting
cfg.Debug.PrintQueryPlans = true inside ModifyEngineExecutionConfiguration which
may clutter CI logs; change this to false (or remove the assignment) so tests
run with PrintQueryPlans disabled, or gate it behind a CI-debug flag (e.g.,
check an env var in ModifyEngineExecutionConfiguration and only set
cfg.Debug.PrintQueryPlans = true when that flag is present) to preserve the
option for local debugging.
🪄 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: d57d7520-1287-4d89-9f3d-93f37d3e5c63

📥 Commits

Reviewing files that changed from the base of the PR and between dcd4e0a and 275a88a.

⛔ Files ignored due to path filters (8)
  • demo/pkg/subgraphs/employees/subgraph/generated/generated.go is excluded by !**/generated/**
  • 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.proto.lock.json 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 (13)
  • demo/pkg/subgraphs/employees/subgraph/employees.go
  • demo/pkg/subgraphs/employees/subgraph/entity.resolvers.go
  • demo/pkg/subgraphs/employees/subgraph/model/models_gen.go
  • demo/pkg/subgraphs/employees/subgraph/schema.graphqls
  • demo/pkg/subgraphs/employees/subgraph/schema.resolvers.go
  • 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/protocol/router_plugin_test.go
  • router-tests/testenv/testdata/configWithGRPC.json
  • router-tests/testenv/testdata/configWithPlugins.json
  • router/go.mod

@github-actions

This comment was marked as outdated.

@github-actions

This comment has been minimized.

@github-actions

This comment was marked as outdated.

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 `@router-tests/operations/testdata/introspection/base-graph-schema.json`:
- Around line 2704-2719: The introspection JSON incorrectly records several
SDL-backed scalar types as String; update the introspection entries for the
fields approvedAt (WorkApproval), rejectionCode (WorkRejection), and priority
(WorkSetup) so their "type" objects reflect the correct NON_NULL SCALAR names
(DateTime for approvedAt, Int for rejectionCode and priority) instead of
"String", and ensure the DateTime scalar appears in the schema "types" list so
it is included in snapshots; apply the same correction to the other occurrences
noted (around the other ranges referenced).
- Around line 2425-2440: The introspection fixture incorrectly types
WorkSetup.priority as Int! whereas the demo SDL declares it as String!;
regenerate the introspection fixture from the composed schema so the
WorkSetup.priority entry (and any other mismatched scalar fields) reflect the
composed schema types (String!), replacing the incorrect "Int" kind/ofType
entries with the correct scalar "String" non-null structure in the fixture.
🪄 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: 178c1b7b-0ea8-4f97-a019-ad50845f69d6

📥 Commits

Reviewing files that changed from the base of the PR and between 275a88a and 702a3a6.

⛔ Files ignored due to path filters (1)
  • demo/pkg/subgraphs/employees/subgraph/generated/generated.go is excluded by !**/generated/**
📒 Files selected for processing (4)
  • router-tests/operations/testdata/introspection/base-graph-schema.json
  • router-tests/operations/testdata/introspection/feature-graph-schema.json
  • router-tests/testenv/testdata/config.json
  • router-tests/testenv/testdata/configWithEdfs.json

@github-actions github-actions bot removed the router label Mar 27, 2026
@Noroth Noroth merged commit 9a303d1 into main Mar 27, 2026
29 checks passed
@Noroth Noroth deleted the ludwig/eng-9226-add-composite-type-support-in-cosmo branch March 27, 2026 11:14
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