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

Better support for custom scalars as input types #1445

Open
nk-coding opened this issue May 13, 2022 · 4 comments
Open

Better support for custom scalars as input types #1445

nk-coding opened this issue May 13, 2022 · 4 comments
Labels
module: generator Issue affects the schema generator and federation code type: enhancement New feature or request

Comments

@nk-coding
Copy link

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 nk-coding added the type: enhancement New feature or request label May 13, 2022
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Jul 22, 2022
Update `kotlinx-serialization` handling of custom scalars to allow non-primitive values. While custom scalars are most often represented as some primitive value (e.g. UUID -> String), there are use cases when scalars need to be represented as objects. One common use case is Apollo Federation and its usage of `_Any` scalar to represent arbitrary entity object map that contains various fields to uniquely identity it.

Updated custom scalar documentation with examples  n how to use arbitrary objects as custom scalars.

Resolves:

* ExpediaGroup#1408
* ExpediaGroup#1435
* ExpediaGroup#1445
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Jul 22, 2022
Update `kotlinx-serialization` handling of custom scalars to allow non-primitive values. While custom scalars are most often represented as some primitive value (e.g. UUID -> String), there are use cases when scalars need to be represented as objects. One common use case is Apollo Federation and its usage of `_Any` scalar to represent arbitrary entity object map that contains various fields to uniquely identity it.

Updated custom scalar documentation with examples  n how to use arbitrary objects as custom scalars.

Resolves:

* ExpediaGroup#1408
* ExpediaGroup#1435
* ExpediaGroup#1445
dariuszkuc added a commit that referenced this issue Jul 26, 2022
Update `kotlinx-serialization` handling of custom scalars to allow non-primitive values. While custom scalars are most often represented as some primitive value (e.g. UUID -> String), there are use cases when scalars need to be represented as objects. One common use case is Apollo Federation and its usage of `_Any` scalar to represent arbitrary entity object map that contains various fields to uniquely identity it.

Updated custom scalar documentation with examples  n how to use arbitrary objects as custom scalars.

Resolves:

* #1408
* #1435
* #1445
@dariuszkuc
Copy link
Collaborator

Resolved by #1488

@nk-coding
Copy link
Author

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?

@dariuszkuc
Copy link
Collaborator

Ah indeed, closed incorrectly.

@dariuszkuc dariuszkuc reopened this Jul 26, 2022
dariuszkuc added a commit to dariuszkuc/graphql-kotlin that referenced this issue Aug 5, 2022
Update `kotlinx-serialization` handling of custom scalars to allow non-primitive values. While custom scalars are most often represented as some primitive value (e.g. UUID -> String), there are use cases when scalars need to be represented as objects. One common use case is Apollo Federation and its usage of `_Any` scalar to represent arbitrary entity object map that contains various fields to uniquely identity it.

Updated custom scalar documentation with examples  n how to use arbitrary objects as custom scalars.

Resolves:

* ExpediaGroup#1408
* ExpediaGroup#1435
* ExpediaGroup#1445
@dariuszkuc dariuszkuc added the module: generator Issue affects the schema generator and federation code label Aug 14, 2022
@stasbit
Copy link

stasbit commented Jul 3, 2024

@dariuszkuc Any ideas on support of Map<K, V> as input argument type? I tryed different options on server side. One was Coercing, but in runtime it thows

PrimaryConstructorNotFound: Invalid input object Map - missing public primary constructor

which was shown in 1808

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
module: generator Issue affects the schema generator and federation code type: enhancement New feature or request
Development

No branches or pull requests

3 participants