Skip to content

Conversation

@ysmolski
Copy link
Contributor

@ysmolski ysmolski commented Aug 6, 2025

This allows to print nodes that would not be included because of directives like "skip", "include".

Depends on wundergraph/graphql-go-tools#1261

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Added a new test case to validate handling of GraphQL queries with @include and @skip directives.
    • Expanded test coverage with additional query and plan files.
  • Bug Fixes

    • Improved normalization of GraphQL operations, ensuring correct handling of directives and fragments during query planning.
  • Chores

    • Updated a dependency to a more specific version for consistency and reliability.

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/cosmo-docs.
  • I have read the Contributors Guide.

@coderabbitai
Copy link

coderabbitai bot commented Aug 6, 2025

Walkthrough

The changes update the normalizeOperation method in the Planner struct to use a configurable normalizer with multiple normalization options. Dependency versions for github.com/wundergraph/graphql-go-tools/v2 are updated in Go modules. New test data and test cases are added to cover scenarios involving GraphQL directives and plan generation. Test setup is improved to dynamically discover test query files.

Changes

Cohort / File(s) Change Summary
Dependency Version Updates
router/go.mod, router-tests/go.mod
Updated the github.com/wundergraph/graphql-go-tools/v2 dependency from v2.0.0-rc.216 to v2.0.0-rc.217. No other dependency changes.
Planner Normalization Refactor
router/core/plan_generator.go
Refactored the normalizeOperation method in the Planner struct to instantiate and use an astnormalization.Normalizer with multiple normalization options instead of calling a single normalization function. No changes to public interfaces.
Test Suite Enhancement
router/pkg/plan_generator/plan_generator_test.go
Modified test setup to dynamically discover all .graphql files in the queries/base directory instead of using a hardcoded list. Updated variable usage accordingly. No other test logic changes.
Test Data Additions
router/pkg/plan_generator/testdata/queries/base/5.graphql,
router/pkg/plan_generator/testdata/plans/base/5.graphql,
router/pkg/plan_generator/testdata/plans/base/report.json
Added a new test query exercising @skip and @include directives with variables, the corresponding expected query plan with sequenced fetches, and an entry in the test report JSON. No modifications to existing test data.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

Note

⚡️ Unit Test Generation is now available in beta!

Learn more here, or try it out under "Finishing Touches" below.


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0274600 and 217e8dc.

⛔ 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 (7)
  • router-tests/go.mod (1 hunks)
  • router/core/plan_generator.go (1 hunks)
  • router/go.mod (1 hunks)
  • router/pkg/plan_generator/plan_generator_test.go (2 hunks)
  • router/pkg/plan_generator/testdata/plans/base/5.graphql (1 hunks)
  • router/pkg/plan_generator/testdata/plans/base/report.json (1 hunks)
  • router/pkg/plan_generator/testdata/queries/base/5.graphql (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • router/go.mod
🚧 Files skipped from review as they are similar to previous changes (6)
  • router-tests/go.mod
  • router/pkg/plan_generator/testdata/queries/base/5.graphql
  • router/pkg/plan_generator/plan_generator_test.go
  • router/pkg/plan_generator/testdata/plans/base/report.json
  • router/core/plan_generator.go
  • router/pkg/plan_generator/testdata/plans/base/5.graphql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
  • GitHub Check: build-router
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: Analyze (go)
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: build_push_image
  • GitHub Check: image_scan
  • GitHub Check: integration_test (./events)
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: build_test
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch yury/eng-7726-skipinclude-should-be-ignored-in-query-plan-generator

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions github-actions bot added the router label Aug 6, 2025
@github-actions
Copy link

github-actions bot commented Aug 6, 2025

Router-nonroot image scan passed

✅ No security vulnerabilities found in image:

ghcr.io/wundergraph/cosmo/router:sha-952dfd02f62cb04fd7f0b0f9981b5947269f5b3d-nonroot

Copy link

@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: 0

🧹 Nitpick comments (2)
router-tests/go.mod (1)

30-31: Keep router-tests in sync with router’s dependency graph

The tests mirror the router’s pseudo-version pin. Make sure you run go mod tidy in both modules so that their transitive graphs stay identical; desynchronisation can surface as hard-to-trace CI failures.

router/pkg/plan_generator/plan_generator_test.go (1)

23-24: Consider deriving allFiles dynamically

Manually enumerating "5.graphql" in allFiles works now but is error-prone whenever new queries are added.
Reading the directory once (e.g. os.ReadDir(...)) would keep the list self-maintaining and avoid missed test coverage.

- allFiles := []string{"1.graphql", "2.graphql", "3.graphql", "4.graphql", "5.graphql"}
+ entries, _ := os.ReadDir(path.Join(getTestDataDir(), "queries", "base"))
+ allFiles := make([]string, 0, len(entries))
+ for _, e := range entries {
+     if !e.IsDir() {
+         allFiles = append(allFiles, e.Name())
+     }
+ }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 589d43b and 6691a7d.

⛔ 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 (7)
  • router-tests/go.mod (1 hunks)
  • router/core/plan_generator.go (1 hunks)
  • router/go.mod (1 hunks)
  • router/pkg/plan_generator/plan_generator_test.go (1 hunks)
  • router/pkg/plan_generator/testdata/plans/base/5.graphql (1 hunks)
  • router/pkg/plan_generator/testdata/plans/base/report.json (1 hunks)
  • router/pkg/plan_generator/testdata/queries/base/5.graphql (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: in go testing, t.fatal, t.failnow, t.skip* and similar methods cannot be called from goroutines othe...
Learnt from: Noroth
PR: wundergraph/cosmo#2088
File: demo/pkg/subgraphs/projects/src/main_test.go:0-0
Timestamp: 2025-07-29T08:19:55.720Z
Learning: In Go testing, t.Fatal, t.FailNow, t.Skip* and similar methods cannot be called from goroutines other than the main test goroutine, as they will cause a runtime panic. Use channels, t.Error*, or other synchronization mechanisms to communicate errors from goroutines back to the main test thread.

Applied to files:

  • router/pkg/plan_generator/plan_generator_test.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (13)
  • GitHub Check: lint
  • GitHub Check: build-router
  • GitHub Check: build_push_image
  • GitHub Check: build_push_image (nonroot)
  • GitHub Check: image_scan
  • GitHub Check: build_test
  • GitHub Check: image_scan (nonroot)
  • GitHub Check: integration_test (./telemetry)
  • GitHub Check: integration_test (./. ./fuzzquery ./lifecycle ./modules)
  • GitHub Check: integration_test (./events)
  • GitHub Check: build_test
  • GitHub Check: Analyze (go)
  • GitHub Check: Analyze (javascript-typescript)
🔇 Additional comments (5)
router/go.mod (1)

34-35: Confirm the pseudo-version pin is intentional

github.com/wundergraph/graphql-go-tools/v2 is now fixed to a commit-based pseudo-version (fa127e0).
Please double-check that:

  1. This commit is pushed to the public upstream and won’t be garbage-collected.
  2. All downstream modules (e.g. private CI caches, mirrors) can fetch it.
  3. No local replace override is accidentally left active – the commented line 165 looks fine.

If a proper tag will be cut shortly, prefer switching to the tag for cleaner go mod tidy output.

router/pkg/plan_generator/testdata/plans/base/report.json (1)

1-1: Test fixture updated – LGTM

The report now contains the expected plan for 5.graphql; structure matches the existing entries.

router/pkg/plan_generator/testdata/queries/base/5.graphql (1)

1-9: Good edge-case coverage for @skip/@include directives

Adding this query ensures the normaliser keeps skipped/included nodes for plan generation – great catch.

router/pkg/plan_generator/testdata/plans/base/5.graphql (1)

1-30: LGTM! Well-structured test data for skip/include directive testing.

The GraphQL query plan follows proper federation patterns with appropriate sequencing of fetch operations. The structure correctly represents the expected output for testing skip/include directive handling where all query nodes are preserved during plan generation.

router/core/plan_generator.go (1)

128-136: Excellent refactor to support skip/include directive preservation.

The change from a single normalization call to a configurable normalizer with explicit options directly addresses the PR objective. The addition of WithIgnoreSkipInclude() ensures that query nodes with skip/include directives are preserved during plan generation, allowing full visibility into all query nodes regardless of their execution status.

The comprehensive set of normalization options maintains existing functionality while adding the required directive handling capability.

@ysmolski ysmolski force-pushed the yury/eng-7726-skipinclude-should-be-ignored-in-query-plan-generator branch from 6691a7d to 0274600 Compare August 6, 2025 11:34
This allows to print all query nodes, even those that would not
be executed because of directives like "skip", "include".
@ysmolski ysmolski force-pushed the yury/eng-7726-skipinclude-should-be-ignored-in-query-plan-generator branch from 0274600 to 217e8dc Compare August 6, 2025 12:31
@ysmolski ysmolski merged commit c935d14 into main Aug 6, 2025
29 checks passed
@ysmolski ysmolski deleted the yury/eng-7726-skipinclude-should-be-ignored-in-query-plan-generator branch August 6, 2025 12:45
@Noroth Noroth mentioned this pull request Sep 30, 2025
5 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants