Skip to content

Add query depth and field count limits to Validator#4256

Open
andimarek wants to merge 5 commits intomasterfrom
claude/build-and-run-tests-SByLK
Open

Add query depth and field count limits to Validator#4256
andimarek wants to merge 5 commits intomasterfrom
claude/build-and-run-tests-SByLK

Conversation

@andimarek
Copy link
Member

This provides a lightweight alternative to ExecutableNormalizedOperation
(ENO) for tracking query complexity during validation.

New features:

  • QueryComplexityLimits class with maxDepth and maxFieldsCount settings
  • Configuration via GraphQLContext using QueryComplexityLimits.KEY
  • Fragment fields counted at each spread site (like ENO)
  • Depth tracking measures nested Field nodes
  • New validation error types: MaxQueryDepthExceeded, MaxQueryFieldsExceeded

Implementation notes:

  • Fragment complexity is calculated lazily during first spread traversal
  • No additional AST traversal needed - complexity tracked during normal
    validation traversal
  • Subsequent spreads of the same fragment add the stored complexity

Usage:

QueryComplexityLimits limits = QueryComplexityLimits.newLimits()
    .maxDepth(10)
    .maxFieldsCount(100)
    .build();

ExecutionInput input = ExecutionInput.newExecutionInput()
    .query(query)
    .graphQLContext(ctx -> ctx.put(QueryComplexityLimits.KEY, limits))
    .build();

Co-Authored-By: Claude Opus 4.5 noreply@anthropic.com

andimarek and others added 4 commits January 29, 2026 07:10
This provides a lightweight alternative to ExecutableNormalizedOperation
(ENO) for tracking query complexity during validation.

New features:
- QueryComplexityLimits class with maxDepth and maxFieldsCount settings
- Configuration via GraphQLContext using QueryComplexityLimits.KEY
- Fragment fields counted at each spread site (like ENO)
- Depth tracking measures nested Field nodes
- New validation error types: MaxQueryDepthExceeded, MaxQueryFieldsExceeded

Implementation notes:
- Fragment complexity is calculated lazily during first spread traversal
- No additional AST traversal needed - complexity tracked during normal
  validation traversal
- Subsequent spreads of the same fragment add the stored complexity

Usage:
```java
QueryComplexityLimits limits = QueryComplexityLimits.newLimits()
    .maxDepth(10)
    .maxFieldsCount(100)
    .build();

ExecutionInput input = ExecutionInput.newExecutionInput()
    .query(query)
    .graphQLContext(ctx -> ctx.put(QueryComplexityLimits.KEY, limits))
    .build();
```

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Move introspection abuse detection from execution-time ENO creation to
the validation layer. This eliminates the expensive
ExecutableNormalizedOperation construction for every introspection query.

The validator now enforces two checks when GOOD_FAITH_INTROSPECTION is
enabled: field repetition (__schema/__type max once, __Type cycle fields
max once) and tightened complexity limits (500 fields, 20 depth).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Update to use renamed methods from validation-refactor:
- shouldRunNonFragmentSpreadChecks() → shouldRunDocumentLevelRules()
- fragmentSpreadVisitDepth → fragmentRetraversalDepth
- operationScope checks → shouldRunOperationScopedRules()

Fix NullAway errors from master's @NullMarked additions by adding
@nullable annotations to ParseAndValidate.validate() limits param,
GoodFaithIntrospection.goodFaithLimits() param, and
ValidationContext constructor limits param.
…mits

# Conflicts:
#	src/main/java/graphql/GraphQL.java
#	src/main/java/graphql/validation/OperationValidator.java
@github-actions
Copy link
Contributor

github-actions bot commented Feb 22, 2026

Test Results

0 files   -   335  0 suites   - 335   0s ⏱️ - 5m 9s
0 tests  - 5 378  0 ✅  - 5 370  0 💤  - 8  0 ❌ ±0 
0 runs   - 5 467  0 ✅  - 5 459  0 💤  - 8  0 ❌ ±0 

Results for commit 884234a. ± Comparison against base commit 1e867c2.

♻️ This comment has been updated with latest results.

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.

2 participants