Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow creation of custom scalars from polymorphic types #1994

Open
Melodeiro opened this issue Jun 30, 2024 · 0 comments
Open

Allow creation of custom scalars from polymorphic types #1994

Melodeiro opened this issue Jun 30, 2024 · 0 comments
Labels
type: enhancement New feature or request

Comments

@Melodeiro
Copy link

Right now an exception is thrown with lists of polymorphic types before fun willGenerateGraphQLType(type: KType): GraphQLType? since #801. My suggestion is to allow users to handle this situation with custom Coercing implementation and throw if no custom scalar type were provided. It is possible already but only with a hack:

override fun willResolveInputMonad(type: KType): KType {
    return when { // MessageContent is sealed class, but MessageContentInput is data class and actually does nothing
        type == typeOf<List<MessageContent>>() -> typeOf<List<MessageContentInput>>()
        else -> super.willResolveInputMonad(type)
    }
}

override fun willGenerateGraphQLType(type: KType): GraphQLType? = when (type.classifier) {
    MessageContentInput::class -> MessageContentScalar // uses Coercing<MessageContent, String>
    else -> null
}
@Melodeiro Melodeiro added the type: enhancement New feature or request label Jun 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Development

No branches or pull requests

1 participant