Repository navigation
Consolidate Good Faith settings in QueryComplexityLimits - #4550
Merged
Merged
Conversation
Contributor
Test ReportTest Results
Code Coverage (Java 25)
Changed Class Coverage (5 classes)
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Good Faith introspection settings currently live outside
QueryComplexityLimits, and its enablement is applied differently by execution and direct validation. This PR puts all of those settings in the same immutable configuration while preserving the special introspection exception and GraphQL error handling.Changes
Adds three builder settings, matching getters, and default constants:
introspectionLimitsEnabled(boolean)truemaxIntrospectionMergedFieldCount(int)500maxIntrospectionDepth(int)20newLimitsWithDefaults()snapshots all six general/introspection settings from the current JVM defaults.transform(...)copies an existing instance independently of those defaults. Toggling introspection preserves its configured thresholds; thresholds must be positive. The diagnostic string includes the new settings.__schemaor__typekeep the smaller of their general and introspection-specific merged-field/depth caps, applied to the whole mixed operation. General occurrence limits remain unchanged. Root detection through fragments/aliases and structural counting of conditional selections are unchanged;__typenamealone does not activate introspection limits.ParseAndValidate.parseAndValidate(schema, input)convenience entry point now also reads request-specific limits; it previously ignored them.GoodFaithIntrospectionExceededand its conversion during execution are preserved. The returned error retains its messages andBadFaithIntrospectionclassification; occurrence failures remain ordinary validation errors.GoodFaithIntrospection.java, the separate JVM/context enablement mechanism, and its unusual-configuration façade. Parser settings and the maximum-validation-error setting are unchanged.Breaking changes and migration
GoodFaithIntrospectionand its configuration APIs are removed without compatibility aliases. Update references and rebuild callers. The default protections remain enabled at 500 merged fields and depth 20. The changes below matter when configuring limits, filtering validation rules, or referring to the old Java error type.1. Move JVM-wide configuration to
QueryComplexityLimits.Replace
isEnabledJvmWide()withQueryComplexityLimits.getDefaultLimits().isIntrospectionLimitsEnabled(). The unusual-configuration façade and itsGoodFaithIntrospectionConfigtype are removed. The new setter returns no previous value; read the current configuration before changing it if needed.2. Replace the request context flag with a limits instance.
The boolean meaning is reversed: old
DISABLED = truebecomesintrospectionLimitsEnabled(false). The old context key is no longer read, including when supplied as a string literal. ReplaceGoodFaithIntrospection.isEnabled(context)by readingisIntrospectionLimitsEnabled()from the context's limits instance, falling back to JVM defaults when absent.Request settings now override JVM defaults in either direction:
.introspectionLimitsEnabled(true)can re-enable protections disabled globally. Builders snapshot defaults at creation; set JVM defaults before creating builders that should inherit them. To preserve an existing request's other settings, use itstransform(...)method.3. Review every use of
QueryComplexityLimits.NONE.Previously,
NONEdisabled general limits but retained Good Faith protection. It now disables both general and introspection protections, including the restricted-coordinate checks. To preserve the previous policy:This retains the default introspection thresholds of 500/20 while leaving general limits disabled. Disabling only introspection, as in steps 1–2, leaves general limits active.
4. Configure protections instead of filtering their validation rule.
OperationValidationRule.GOOD_FAITH_INTROSPECTIONis removed. Remove references to that enum member and use.introspectionLimitsEnabled(false)where disabling the protections is intended. Even a predicate that deselects every validation rule now leaves configured introspection protections active.Direct validation reads the same limits as execution.
ParseAndValidate.parseAndValidate(schema, input)now also honors all request-context complexity settings, including general limits it previously ignored. Pass the intended limits and update tests that relied on those settings being ignored. Direct validation still throwsGoodFaithIntrospectionExceeded; execution still converts it to the special GraphQL error.5. Update imports and type checks for the relocated error.
Replace
graphql.introspection.GoodFaithIntrospection.BadFaithIntrospectionErrorwithgraphql.introspection.BadFaithIntrospectionError. Its messages, serialized representation andBadFaithIntrospectionclassification are unchanged. Occurrence-limit failures remain ordinary validation errors.6. Migrate constants and the old limit helper.
GoodFaithIntrospectionGOOD_FAITH_MAX_MERGED_FIELD_COUNTQueryComplexityLimits.DEFAULT_MAX_INTROSPECTION_MERGED_FIELD_COUNT(500)GOOD_FAITH_MAX_DEPTH_COUNTQueryComplexityLimits.DEFAULT_MAX_INTROSPECTION_DEPTH(20)goodFaithLimits(existing)To customize thresholds, use
.maxIntrospectionMergedFieldCount(n)and.maxIntrospectionDepth(n). Read configured values through the matching getters; the effective caps remain the smaller general/introspection values. Update exacttoString()assertions to include the three new settings.Verification
Existing alias, fragment, mixed-operation, directive, restricted-coordinate and general-limit coverage is retained. New tests cover configurable caps above and below defaults, JVM snapshots, request overrides in both directions,
NONE, toggling without losing thresholds, rule-predicate independence, and exact special-error messages/classification/serialization through execution and direct validation.BaseConfighas 100% line and method coverage locally. PR checks show the full Java 17/21/25 matrix and coverage-guard results for the latest commit.