Skip to content

fix: fix insufficient validation of fragment condition - #649

Merged
stuebingerb merged 1 commit into
mainfrom
fix/fix-fragment-type-validation
Jun 14, 2026
Merged

fix: fix insufficient validation of fragment condition#649
stuebingerb merged 1 commit into
mainfrom
fix/fix-fragment-type-validation

Conversation

@stuebingerb

Copy link
Copy Markdown
Owner

Resolves #648

@coderabbitai

coderabbitai Bot commented Jun 14, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@stuebingerb, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 1 minute and 24 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans include higher PR review limits than trial, open-source, and free plans. In all cases, reviews become available again over time. During sustained high-volume PR review activity, CodeRabbit may temporarily slow when the next review becomes available.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 26f3e9be-5369-4e7c-b5dd-f600175c480c

📥 Commits

Reviewing files that changed from the base of the PR and between b618a31 and 54684ec.

📒 Files selected for processing (4)
  • kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/ParallelRequestExecutor.kt
  • kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/structure/RequestInterpreter.kt
  • kgraphql/src/test/kotlin/com/apurebase/kgraphql/integration/QueryTest.kt
  • kgraphql/src/test/kotlin/com/apurebase/kgraphql/specification/language/FragmentsSpecificationTest.kt
📝 Walkthrough

Walkthrough

RequestInterpreter gains a new findFragmentConditionType helper that centralizes type-condition validation for both named and inline fragments, replacing a direct allTypesByName map lookup and the removed unknownFragmentTypeException helper. Fragment spread resolution now throws ValidationException inline. Tests in FragmentsSpecificationTest and QueryTest are updated to match corrected error messages and coverage.

Changes

Fragment Type-Condition Validation

Layer / File(s) Summary
Centralized fragment condition validation
kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/structure/RequestInterpreter.kt, kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/ParallelRequestExecutor.kt
Introduces findFragmentConditionType(ASTNode): Type which validates that a type condition refers to an existing, non-input type; fragment definition and inline fragment resolution both delegate to this helper. Fragment spread resolution now throws ValidationException directly when a named fragment is not found. unknownFragmentTypeException is removed. ParallelRequestExecutor receives a minor error-message adjustment on the unsupported-fragment-target path.
Test updates for corrected validation behavior
kgraphql/src/test/kotlin/com/apurebase/kgraphql/specification/language/FragmentsSpecificationTest.kt, kgraphql/src/test/kotlin/com/apurebase/kgraphql/integration/QueryTest.kt
FragmentsSpecificationTest replaces the old enum-type denial block with shouldBe assertions covering enum, scalar, input, and unknown-type conditions for both inline and named fragments, and adds a new test for missing named fragment references. Three test function names are updated to "should be" wording. QueryTest removes two relocated tests, adds a missing-selection-set validation test, and extends the mixed-selections assertion with a __typename check.

Possibly related PRs

  • stuebingerb/KGraphQL#647: Modifies RequestInterpreter's fragment type-condition resolution in the same area (removal of queryTypes/inputTypes, new input/output type classification), directly motivating the validation gap fixed by this PR.

Suggested reviewers

  • mervyn-mccreight
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 11.76% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix: fix insufficient validation of fragment condition' is descriptive, follows conventional commits specification with 'fix:' prefix, clearly summarizes the main change, and is 54 characters in length.
Description check ✅ Passed The description 'Resolves #648' is directly related to the changeset and indicates the linked issue being addressed by the pull request.
Linked Issues check ✅ Passed The PR fully addresses issue #648 by implementing proper validation of fragment conditions on unknown types, preventing NoSuchElementException and returning user-friendly GraphQL validation errors instead.
Out of Scope Changes check ✅ Passed All changes are directly related to issue #648: fragment validation improvements in RequestInterpreter and ParallelRequestExecutor, plus corresponding test updates.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/fix-fragment-type-validation

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

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/structure/RequestInterpreter.kt`:
- Around line 148-152: The type resolution logic in RequestInterpreter.kt (lines
148-152) incorrectly skips type-condition validation when directives are
present. The current condition checks if directives exist and defaults to
enclosingType, bypassing the findFragmentConditionType call that validates
explicit type conditions. Remove the directive-based branching and always call
findFragmentConditionType for all inline fragments, ensuring that explicit type
conditions are validated regardless of whether directives are present.
Additionally, add a regression test case that covers inline fragments with both
an explicit typeCondition and directives to prevent this validation bypass in
the future.
🪄 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: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6a606fa5-a977-4bb4-9468-bfeee7b36a38

📥 Commits

Reviewing files that changed from the base of the PR and between e0a5fa0 and b618a31.

📒 Files selected for processing (4)
  • kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/execution/ParallelRequestExecutor.kt
  • kgraphql/src/main/kotlin/com/apurebase/kgraphql/schema/structure/RequestInterpreter.kt
  • kgraphql/src/test/kotlin/com/apurebase/kgraphql/integration/QueryTest.kt
  • kgraphql/src/test/kotlin/com/apurebase/kgraphql/specification/language/FragmentsSpecificationTest.kt
💤 Files with no reviewable changes (1)
  • kgraphql/src/test/kotlin/com/apurebase/kgraphql/integration/QueryTest.kt

@codecov

codecov Bot commented Jun 14, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 81.81818% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.22%. Comparing base (e0a5fa0) to head (54684ec).

Files with missing lines Patch % Lines
...se/kgraphql/schema/structure/RequestInterpreter.kt 85.71% 1 Missing and 2 partials ⚠️
...raphql/schema/execution/ParallelRequestExecutor.kt 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #649      +/-   ##
==========================================
+ Coverage   84.19%   84.22%   +0.02%     
==========================================
  Files         151      151              
  Lines        4992     5000       +8     
  Branches      857      857              
==========================================
+ Hits         4203     4211       +8     
- Misses        490      491       +1     
+ Partials      299      298       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 4 files

Architecture diagram
sequenceDiagram
    participant Client as GraphQL Client
    participant Executor as ParallelRequestExecutor
    participant Interpreter as RequestInterpreter
    participant Schema as Schema Model
    participant Type as Type System

    Note over Client,Type: Fragment Condition Validation Flow

    Client->>Executor: execute(query with fragments)
    Executor->>Interpreter: interpret(executables)
    
    Interpreter->>Interpreter: findFragmentConditionType(fragment)
    
    alt Fragment definition (named fragment)
        Interpreter->>Schema: allTypesByName[typeName]
        Schema-->>Interpreter: Type or null
        alt Type NOT found
            Interpreter->>Interpreter: throw ValidationException("Unknown type 'XXX'...")
            Interpreter-->>Executor: Error
            Executor-->>Client: Validation error response
        else Type found
            Interpreter->>Type: isInputType()
            alt Type is input type (ENUM, SCALAR, INPUT_OBJECT)
                Interpreter->>Interpreter: throw ValidationException("Fragments can only be on object/interface/union...")
                Interpreter-->>Executor: Error
                Executor-->>Client: Validation error response
            else Type is object/interface/union
                Interpreter->>Interpreter: return Type
                Interpreter-->>Executor: Valid fragment
                Executor->>Executor: handleFragment(ctx, value, ...)
                Executor-->>Client: Query result
            end
        end
    else Inline fragment
        Interpreter->>Interpreter: extract typeCondition.name
        Interpreter->>Schema: allTypesByName[typeName]
        Schema-->>Interpreter: Type or null
        alt Type NOT found
            Interpreter->>Interpreter: throw ValidationException("Unknown type 'XXX'...")
        else Type found
            Interpreter->>Type: isInputType()
            alt Type is input type
                Interpreter->>Interpreter: throw ValidationException("Fragments can only be on object/interface/union...")
            else Type is valid
                Interpreter->>Interpreter: return Type
            end
        end
    end

    Note over Interpreter,Type: CHANGED: Unified validation in findFragmentConditionType()
    Note over Interpreter: Validates type existence AND type kind
    Note over Interpreter: Returns proper error messages with fragment name context
Loading

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown

🐰 Bencher Report

Branchfix/fix-fragment-type-validation
Testbedubuntu-latest
Click to view all benchmark results
BenchmarkThroughputBenchmark Result
operations / second (ops/s)
(Result Δ%)
Lower Boundary
operations / second (ops/s)
(Limit %)
com.apurebase.kgraphql.FunctionExecutionBenchmark.benchmarkFunctionExecution📈 view plot
🚷 view threshold
7,242,624.30 ops/s
(+24.18%)Baseline: 5,832,312.99 ops/s
5,039,889.70 ops/s
(69.59%)
com.apurebase.kgraphql.ParallelExecutionBenchmark.queryBenchmark📈 view plot
🚷 view threshold
1.30 ops/s
(+0.17%)Baseline: 1.30 ops/s
1.29 ops/s
(99.62%)
com.apurebase.kgraphql.QueryBenchmark.executionError📈 view plot
🚷 view threshold
28,743.40 ops/s
(+66.23%)Baseline: 17,291.81 ops/s
10,720.81 ops/s
(37.30%)
com.apurebase.kgraphql.QueryBenchmark.inputFromDocument📈 view plot
🚷 view threshold
31,968.67 ops/s
(+46.70%)Baseline: 21,792.26 ops/s
14,700.87 ops/s
(45.99%)
com.apurebase.kgraphql.QueryBenchmark.inputFromVariable📈 view plot
🚷 view threshold
30,731.20 ops/s
(+46.98%)Baseline: 20,908.32 ops/s
14,052.48 ops/s
(45.73%)
com.apurebase.kgraphql.QueryBenchmark.largeList📈 view plot
🚷 view threshold
5.67 ops/s
(+25.54%)Baseline: 4.52 ops/s
3.82 ops/s
(67.45%)
com.apurebase.kgraphql.QueryBenchmark.largeListWithFragment📈 view plot
🚷 view threshold
6.70 ops/s
(+32.94%)Baseline: 5.04 ops/s
4.28 ops/s
(63.96%)
com.apurebase.kgraphql.QueryBenchmark.manyChildren📈 view plot
🚷 view threshold
242.66 ops/s
(+30.24%)Baseline: 186.32 ops/s
144.94 ops/s
(59.73%)
com.apurebase.kgraphql.QueryBenchmark.manyChildrenWithFragment📈 view plot
🚷 view threshold
262.76 ops/s
(+27.42%)Baseline: 206.21 ops/s
153.09 ops/s
(58.26%)
com.apurebase.kgraphql.QueryBenchmark.manyDataChildren📈 view plot
🚷 view threshold
9.14 ops/s
(+2.35%)Baseline: 8.93 ops/s
8.80 ops/s
(96.28%)
com.apurebase.kgraphql.QueryBenchmark.manyOperations📈 view plot
🚷 view threshold
397.16 ops/s
(+40.88%)Baseline: 281.92 ops/s
212.95 ops/s
(53.62%)
com.apurebase.kgraphql.QueryBenchmark.manyOperationsWithFragment📈 view plot
🚷 view threshold
414.16 ops/s
(+41.94%)Baseline: 291.78 ops/s
221.68 ops/s
(53.53%)
com.apurebase.kgraphql.QueryBenchmark.nestedObject📈 view plot
🚷 view threshold
11,862.09 ops/s
(+58.21%)Baseline: 7,497.74 ops/s
5,526.26 ops/s
(46.59%)
com.apurebase.kgraphql.RequestCachingBenchmark.invalidRequest📈 view plot
🚷 view threshold
187,589.63 ops/s
(-8.96%)Baseline: 206,060.34 ops/s
115,880.26 ops/s
(61.77%)
com.apurebase.kgraphql.RequestCachingBenchmark.largeRequest📈 view plot
🚷 view threshold
11,948.76 ops/s
(+53.72%)Baseline: 7,773.13 ops/s
5,808.16 ops/s
(48.61%)
com.apurebase.kgraphql.RequestCachingBenchmark.smallRequest📈 view plot
🚷 view threshold
17,541.87 ops/s
(+54.35%)Baseline: 11,365.31 ops/s
8,175.31 ops/s
(46.60%)
com.apurebase.kgraphql.SimpleExecutionOverheadBenchmark.benchmark📈 view plot
🚷 view threshold
635,502.48 ops/s
(+34.28%)Baseline: 473,282.95 ops/s
418,681.67 ops/s
(65.88%)
🐰 View full continuous benchmarking report in Bencher

@stuebingerb
stuebingerb force-pushed the fix/fix-fragment-type-validation branch from b618a31 to df7095a Compare June 14, 2026 11:42
@stuebingerb

Copy link
Copy Markdown
Owner Author

Review limit reached for coderabbit, that seems... quick.

@stuebingerb
stuebingerb force-pushed the fix/fix-fragment-type-validation branch from df7095a to d57c4fc Compare June 14, 2026 11:57
@stuebingerb
stuebingerb force-pushed the fix/fix-fragment-type-validation branch from d57c4fc to 54684ec Compare June 14, 2026 12:06
@stuebingerb
stuebingerb merged commit f608ae3 into main Jun 14, 2026
11 of 12 checks passed
@stuebingerb
stuebingerb deleted the fix/fix-fragment-type-validation branch June 14, 2026 15:39
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.

Insufficient validation of fragment condition

1 participant