dgs-framework
dgs-framework copied to clipboard
bug: Kotlin type in custom type mapping can not be a Kotlin type #704
build.gradle.kts
tasks {
generateJava {
schemaPaths = mutableListOf("${projectDir}/src/main/resources/schema") // List of directories containing schema files
packageName = "com.something" // The package name to use to generate sources
generateClient = true // Enable generating the type safe query API
language = "kotlin"
typeMapping = mutableMapOf("JSON" to "kotlin.String")
}
}
schema.graphqls
"""A JSON formated string."""
scalar JSON
type ColumnValue {
"""The column value's additional information."""
additional_info: JSON
}
Expected behavior
everything is compiled
Actual behavior
kotlin.String is not found during compiling .java class and if I change it to java.lang.String then it shows me that I should use kotlin.String
> Task :compileJava
D:\projects\others\tgbot\build\generated\com\...\client\Change_column_valueGraphQLQuery.java:16: error: cannot find symbol
kotlin.String value, Boolean create_labels_if_missing, Set<String> fieldsSet) {
^
symbol: class String
location: package kotlin
Steps to reproduce
- Compile the configuration above.
@evser for the primitive type (nonspecific to the language) you can use
typeMapping = mutableMapOf("JSON" to "String")
Error:

Generated file:

Configuration:

schema.graphqls file:
scalar JSON#JSON
"""The value of an items column"""
type ColumnValue {
"""The column value's additional information."""
additional_info: JSON#JSON
@berngp @npwork, so unfortunately it does not work
@evser I believe it was fixed as part of 5.1.10. I've fixed it in PR https://github.com/Netflix/dgs-codegen/pull/293 which is part of the release.
Can you please try with dgs-codegen plugin version 5.1.10?
@npwork I have tried, but still have import String with error generated in .kt files:

@evser you are right, reproduced it. Will fix it and come back to you.
@evser meanwhile can you try to replace typeMapping to:
typeMapping = mutableMapOf("JSON" to "kotlin.String")
Fix is available in PR: https://github.com/Netflix/dgs-codegen/pull/303
@npwork ("JSON" to "kotlin.String") does not work, as Queries are generated as .java files
