graphql-kotlin icon indicating copy to clipboard operation
graphql-kotlin copied to clipboard

Better support for custom scalars as input types

Open nk-coding opened this issue 3 years ago • 4 comments

Is your feature request related to a problem? Please describe. Consider the following query:

fun echo(json: JsonNode?): JsonNode? = json

The type JsonNode is an abstract class and resolved to a custom scalar as explained in the documentation:

fun schemaGeneratorHooks() = object : SchemaGeneratorHooks {
    override fun willGenerateGraphQLType(type: KType): GraphQLType? {
        return when (type.classifier) {
            JsonNode::class -> jsonScalar
            else -> null
        }
    }
}

However, this does not work. JsonNode is an abstract class, and generateArgument.kt disallows those before resolving the type using the schema generator hooks.

Describe the solution you'd like Move the check, that no interface / union would be generated from generateArgument.kt to objectFromReflection (of course only check if it is an input type).

Describe alternatives you've considered Currently, I use a workaround where I use Any as Kotlin type and specify the scalar using @GraphQLType, however, this results in unnecessary casts.

nk-coding avatar May 13 '22 09:05 nk-coding

Resolved by https://github.com/ExpediaGroup/graphql-kotlin/pull/1488

dariuszkuc avatar Jul 26 '22 03:07 dariuszkuc

I'm not sure if this is resolved
#1488 looks like a client feature to, however this issue was meant as server-related issue
Or did I overlook something?

nk-coding avatar Jul 26 '22 06:07 nk-coding

Ah indeed, closed incorrectly.

dariuszkuc avatar Jul 26 '22 14:07 dariuszkuc