Skip to content

Better support for custom scalars as input types #1445

Open
@nk-coding

Description

@nk-coding

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    module: generatorIssue affects the schema generator and federation codetype: enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions