-
Notifications
You must be signed in to change notification settings - Fork 157
fix: omit introspection queries from complexity limits #1332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: omit introspection queries from complexity limits #1332
Conversation
This is disabled by default and should stay like that for now. There is a constant that can enable it again, but it is not intended to be tweaked by the clients.
WalkthroughAdds runtime skipping of GraphQL introspection fields (__schema and __type) in operation complexity middleware and renames a local directive-skip flag; updates tests and test schema to cover skipped nodes and an @nodeCountSkip field. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
participant Client
participant Parser
participant ComplexityMiddleware
participant MetricsCollector
Client->>Parser: send GraphQL request
Parser->>ComplexityMiddleware: EnterField(field)
alt field is introspection (__schema/__type) and skipIntrospection == true
ComplexityMiddleware--x MetricsCollector: skip node counting
note right of ComplexityMiddleware #B7E4C7: field ignored at runtime
else check @nodeCountSkip directive
alt directive present
ComplexityMiddleware--x MetricsCollector: skip node counting
note right of ComplexityMiddleware #FCE7C6: directive-based skip
else
ComplexityMiddleware->>MetricsCollector: record NodeCount/Complexity/Depth
end
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Pre-merge checks and finishing touches✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
⏰ 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). (4)
🔇 Additional comments (1)
Comment |
There was a problem hiding this 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)
v2/pkg/middleware/operation_complexity/operation_complexity.go (2)
2-24: Update documentation to reflect runtime introspection skipping.The documentation at lines 22-23 mentions using
@nodeCountSkipfor introspection allowlisting, but the implementation now skips__schemaand__typefields via a runtime check (lines 202-205). Consider updating the docs to clarify that introspection fields are skipped automatically, while@nodeCountSkipcan be used for other fields.Apply this diff to update the documentation:
"nodeCountMultiply" indicates that the Int value the directive is applied on should be used as a Node multiplier. -"nodeCountSkip" indicates that the algorithm should skip this Node. -It can be used to allowlist certain query paths, e.g. for introspection. +"nodeCountSkip" indicates that the algorithm should skip this Node. +It can be used to allowlist certain query paths. + +Note: Introspection fields (__schema and __type) are automatically skipped +from complexity calculations by default.
51-55: Consider makingskipIntrospectionconfigurable or document its purpose.The
skipIntrospectionconstant is set totrueand the PR description mentions it's not intended to be modified by clients. If this is for internal debugging/testing only, consider adding a comment explaining this. Alternatively, if there's a use case for disabling introspection skipping, consider making it a configuration option rather than a package-level constant.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
go.work.sumis excluded by!**/*.sum
📒 Files selected for processing (2)
v2/pkg/middleware/operation_complexity/operation_complexity.go(3 hunks)v2/pkg/middleware/operation_complexity/operation_complexity_test.go(3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
v2/pkg/middleware/operation_complexity/operation_complexity_test.go (1)
v2/pkg/middleware/operation_complexity/operation_complexity.go (2)
OperationStats(33-37)RootFieldStats(39-44)
⏰ 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). (4)
- GitHub Check: Build and test (go 1.25 / ubuntu-latest)
- GitHub Check: Build and test (go 1.25 / windows-latest)
- GitHub Check: Build and test (go 1.25 / ubuntu-latest)
- GitHub Check: Build and test (go 1.25 / windows-latest)
🔇 Additional comments (4)
v2/pkg/middleware/operation_complexity/operation_complexity.go (1)
196-205: LGTM! Clean implementation of introspection field skipping.The runtime check correctly identifies and skips
__schemaand__typefields whenskipIntrospectionis enabled. The implementation properly:
- Checks the directive-based skip first (preserving existing behavior)
- Uses the defined constants for field name comparison
- Skips only root-level introspection fields (
__schema,__type) while allowing__typenamein regular queriesv2/pkg/middleware/operation_complexity/operation_complexity_test.go (3)
42-42: Good addition for test coverage.Adding
__typenameto the test query verifies that it's not incorrectly skipped by the introspection check. This is correct behavior since__typenameis commonly used in regular queries for type discrimination, not just introspection.
70-86: Excellent test coverage for directive-based skipping.This test case verifies that the
@nodeCountSkipdirective continues to work correctly alongside the new runtime introspection skipping. The expectations are correct: when a root field is skipped via the directive, all complexity metrics should be zero andRootFieldStatsshould be empty.
613-618: Schema changes align well with the implementation.The removal of
@nodeCountSkipfrom__schema(line 613) and addition ofactiveUserswith the directive (line 618) properly test both skipping mechanisms:
- Introspection fields (
__schema,__type) are now skipped via runtime check- The
activeUsersfield tests that directive-based skipping still worksThis ensures both code paths are covered by tests.
🤖 I have created a release *beep* *boop* --- ## [2.0.0-rc.233](v2.0.0-rc.232...v2.0.0-rc.233) (2025-10-23) ### Bug Fixes * omit introspection queries from complexity limits ([#1332](#1332)) ([971a239](971a239)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes (v2 2.0.0-rc.233) * **Bug Fixes** * Fixed an issue where introspection queries were incorrectly counted toward complexity limits. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
This is disabled by default and should stay like that for now. There is a constant that can enable it again, but it is not intended to be tweaked by the clients.
Summary by CodeRabbit
Bug Fixes
Tests