feat: validate input types during schema compilation - #713
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughSchema compilation now rejects interfaces, sealed classes, and abstract classes as input types with specific ChangesInput Type Validation
Merge Risk: ⚪ Minimal · up to This change moves invalid input-type failures to schema compilation and improves the related error message; no actionable merge-blocking risk remains beyond normal checks and review. 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID: cf633ac2-cd7e-4d25-b166-37efa3096f34
📒 Files selected for processing (2)
kgraphql/src/main/kotlin/de/stuebingerb/kgraphql/schema/structure/SchemaCompilation.ktkgraphql/src/test/kotlin/de/stuebingerb/kgraphql/specification/typesystem/InputObjectsSpecificationTest.kt
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #713 +/- ##
==========================================
+ Coverage 84.05% 84.10% +0.05%
==========================================
Files 151 151
Lines 4930 4933 +3
Branches 853 855 +2
==========================================
+ Hits 4144 4149 +5
+ Misses 488 487 -1
+ Partials 298 297 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Architecture diagram
sequenceDiagram
participant App as Application
participant Comp as SchemaCompilation
participant Resolver as Resolver Builder
participant Input as handleInputType()
participant Output as handleOutputType()
Note over App,Output: PR: Input type validation during schema compilation
App->>Comp: Build schema (query + input types)
Comp->>Resolver: Resolve query resolver
Resolver->>Comp: Returns type reference
Comp->>Comp: Determine TypeCategory (QUERY/INPUT)
alt TypeCategory == QUERY (output position)
Comp->>Output: Handle output type
alt Class is sealed
Output-->>Comp: TypeDef.Union
Note over Output: Sealed classes allowed as output types
else Class is not sealed
Output-->>Comp: Regular output type
end
else TypeCategory == INPUT
alt Class is sealed
Comp->>Input: Validate input class
Input-->>Comp: SchemaException ("Sealed class ... not allowed as input type")
Comp-->>App: Throw at compile time
else Class is interface
Input-->>Comp: SchemaException ("Interface ... not allowed as input type")
Comp-->>App: Throw at compile time
else Class is abstract
Input-->>Comp: SchemaException ("Abstract class ... not allowed as input type")
Comp-->>App: Throw at compile time
else Class is valid input type
Input->>Input: Validate primary constructor
Input-->>Comp: TypeDef.InputObject
Comp-->>App: Schema compiled successfully
end
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
2adb1a5 to
508d558
Compare
There was a problem hiding this comment.
All reported issues were addressed across 2 files
Architecture diagram
sequenceDiagram
participant SchemaBuilder as Schema Builder
participant Compiler as SchemaCompilation
participant TypeHandler as Type Handler
participant QueryType as Query Type Resolver
participant InputType as Input Type Handler
participant Validator as Validator
Note over SchemaBuilder,Validator: Schema compilation and type validation flow
SchemaBuilder->>Compiler: Build schema
Compiler->>QueryType: Handle query type
QueryType->>TypeHandler: Resolve query type
TypeHandler->>TypeHandler: Check sealed class
alt Sealed class and QUERY category
TypeHandler->>TypeHandler: Create Union type
else Sealed class and INPUT category
TypeHandler->>InputType: Handle as input type
end
Compiler->>InputType: Handle input type
InputType->>Validator: Validate input type
alt Input type is interface
Validator-->>InputType: Validation error
InputType-->>Compiler: SchemaException - Interface not allowed
Compiler-->>SchemaBuilder: Propagate schema error
else Input type is sealed class
Validator-->>InputType: Validation error
InputType-->>Compiler: SchemaException - Sealed class not allowed
Compiler-->>SchemaBuilder: Propagate schema error
else Input type is abstract class
Validator-->>InputType: Validation error
InputType-->>Compiler: SchemaException - Abstract class not allowed
Compiler-->>SchemaBuilder: Propagate schema error
else Input type is valid
Validator-->>InputType: Valid input type
InputType->>InputType: Get primary constructor
alt No primary constructor
InputType-->>Compiler: SchemaException - Java class unsupported
Compiler-->>SchemaBuilder: Propagate schema error
else Constructor exists
InputType-->>Compiler: Continue processing
Compiler-->>SchemaBuilder: Schema compiled successfully
end
end
Reply with feedback, questions, or to request a fix.
Re-trigger cubic
Ensures that abstract and sealed classes as input types are already caught at schema compilation instead of failing at runtime, and improves the error message for interfaces as input types. Resolves #712
508d558 to
5c423ff
Compare
| when (val type = unions.find { it.name == kClass.simpleName }) { | ||
| null -> Unit | ||
| else -> return type | ||
| } | ||
|
|
There was a problem hiding this comment.
These lines were added with aPureBase/KGraphQL#110 but the corresponding test (moved to UnionsSpecificationTest#list of union type should work as expected) still runs successfully. In fact, the only test that even reached line 293 was the new use case added in input objects must not be sealed classes - and that clearly shouldn't have, so... unsure what impact this has, I wasn't able to come up with a test that would break.
There was a problem hiding this comment.
No issues found across 2 files
Architecture diagram
sequenceDiagram
participant Client as "Client/Test"
participant Schema as "KGraphQL.schema builder"
participant Compiler as "SchemaCompilation"
participant InputHandler as "handleInputType()"
participant TypeRegistry as "Type Proxies/Registry"
participant Validator as "assertValidObjectType()"
Note over Client,Validator: Schema Compilation - Input Type Validation Flow
Client->>Schema: Build schema with query/type/inputType definitions
Schema->>Compiler: Compile schema
Compiler->>Compiler: handlePossiblyWrappedType()
alt TypeCategory == QUERY
Compiler->>Compiler: Handle as output type
else TypeCategory == INPUT
Compiler->>InputHandler: delegate to handleInputType(kClass)
InputHandler->>Validator: assertValidObjectType(kClass)
alt kClass is Interface
InputHandler->>InputHandler: CHANGED: Detect interface type
InputHandler->>Schema: Throw SchemaException
Note over InputHandler,Schema: Interface 'X' is not allowed as input type
else kClass is Sealed class
InputHandler->>InputHandler: CHANGED: Detect sealed class type
InputHandler->>Schema: Throw SchemaException
Note over InputHandler,Schema: Sealed class 'X' is not allowed as input type
else kClass is Abstract class
InputHandler->>InputHandler: CHANGED: Detect abstract class type
InputHandler->>Schema: Throw SchemaException
Note over InputHandler,Schema: Abstract class 'X' is not allowed as input type
else Valid concrete class
InputHandler->>InputHandler: Process primary constructor
InputHandler->>TypeRegistry: Check for existing cached types
alt Cached type found
TypeRegistry-->>InputHandler: Return cached type
else No cache
InputHandler->>TypeRegistry: Register new input type
TypeRegistry-->>Schema: Return compiled type
end
end
end
Note over Schema,Validator: Nested type validation (recursive)
Compiler->>Compiler: Handle nested generic types
Compiler->>InputHandler: Recursively validate nested input fields
InputHandler->>Validator: Validate nested type class
alt Nested type is abstract/sealed/interface
Validator-->>InputHandler: Invalid type detected
InputHandler->>Schema: Throw SchemaException
else Valid nested type
Validator-->>InputHandler: Validation passed
InputHandler-->>Compiler: Continue compilation
end
Note over Client,Schema: Cached Type Lookup (CHANGED behavior)
Compiler->>TypeRegistry: Check cached instances
alt Query type category
TypeRegistry-->>Compiler: Check queryTypeProxies
else Input type category
TypeRegistry-->>Compiler: Check inputTypeProxies
end
opt No cached type found
Compiler->>InputHandler: Create new type definition
InputHandler-->>Compiler: Return type
end
Compiler-->>Schema: Compiled schema with validated types
Schema-->>Client: Return schema or throw SchemaException
Ensures that abstract and sealed classes as input types are already caught at schema compilation instead of failing at runtime, and improves the error message for interfaces as input types.
Resolves #712