dgs-framework icon indicating copy to clipboard operation
dgs-framework copied to clipboard

bug: Kotlin type in custom type mapping can not be a Kotlin type #704

Open evser opened this issue 4 years ago • 8 comments

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

  1. Compile the configuration above.

evser avatar Oct 21 '21 15:10 evser

@evser for the primitive type (nonspecific to the language) you can use

typeMapping = mutableMapOf("JSON" to "String")

npwork avatar Nov 24 '21 11:11 npwork

Error:

image

Generated file: image

Configuration: image

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 avatar Dec 01 '21 11:12 evser

@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 avatar Dec 06 '21 19:12 npwork

@npwork I have tried, but still have import String with error generated in .kt files:

image

evser avatar Dec 10 '21 16:12 evser

@evser you are right, reproduced it. Will fix it and come back to you.

npwork avatar Dec 11 '21 12:12 npwork

@evser meanwhile can you try to replace typeMapping to:

typeMapping = mutableMapOf("JSON" to "kotlin.String")

npwork avatar Dec 11 '21 12:12 npwork

Fix is available in PR: https://github.com/Netflix/dgs-codegen/pull/303

npwork avatar Dec 11 '21 14:12 npwork

@npwork ("JSON" to "kotlin.String") does not work, as Queries are generated as .java files

image

evser avatar Dec 14 '21 14:12 evser