Repository navigation
Handle object literal default values on custom scalar input fields - #985
Open
reginaldalfret wants to merge 1 commit into
Open
reginaldalfret wants to merge 1 commit into
reginaldalfret wants to merge 1 commit into
Conversation
When an input field type is a custom scalar with an object literal default value (e.g. metadata: JSON = {}), the default value generators in DataTypeGenerator (Java) and GenerateKotlinCode (Kotlin) previously assumed the field type was an input object and invoked inputTypeDefinitions.first { ... }, throwing NoSuchElementException because no input type definition matches.
Additionally, JavaTypeName.className and TypeName.className assumed ParameterizedTypeName was always a List and accessed the first type argument, which returned the key type rather than raw Map when mapped to a Map.
This change:
1. Uses firstOrNull in DataTypeGenerator and GenerateKotlinCode to gracefully handle non-input-object types, emitting emptyMap() or fallback initializers for Map scalars.
2. Updates JavaTypeName.className and TypeName.className to preserve rawType for non-List parameterized types like Map.
3. Uses cross-platform File.pathSeparator in TestUtils.classpath().
4. Adds regression tests for both Java and Kotlin code generation.
Signed-off-by: reginaldalfret <reginaldalfret@gmail.com>
reginaldalfret
requested review from
asibross,
iparadiso,
iuliiasobolevska,
jjacobs44,
kzwang,
paulbakker and
srinivasankavitha
as code owners
October 25, 2026 14:37
This branch has not been deployed
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.
Fixes #982
Problem
When an input field type is a custom scalar with an object literal default value (for example: \metadata: JSON = {}), the default value generators in \DataTypeGenerator.kt\ (Java) and \GenerateKotlinCode.kt\ (Kotlin) assumed the field type was an input object and called \inputTypeDefinitions.first { ... }. This threw \NoSuchElementException: Collection contains no element matching the predicate.\ because custom scalars are not present in \inputTypeDefinitions.
Furthermore, \JavaTypeName.className\ and \TypeName.className\ assumed any \ParameterizedTypeName\ was a \List\ and grabbed \ ypeArguments().first().className, which extracted the key type (e.g. \String) instead of the raw type \Map\ when mapped to a \Map<String, Object>.
Solution