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

Impossible to define scalars for input parameters in Kotlin2 generated code #455

Closed
giacomo-porro opened this issue Aug 31, 2022 · 2 comments · Fixed by #675 · May be fixed by #611
Closed

Impossible to define scalars for input parameters in Kotlin2 generated code #455

giacomo-porro opened this issue Aug 31, 2022 · 2 comments · Fixed by #675 · May be fixed by #611

Comments

@giacomo-porro
Copy link

I am using dgs-codegen successfully since a couple of months. I saw that recently a new so called kotlin2 code generation has been added and wanted to give it a try.

I have to say I really like the way the code generation works and I'd like to use it instead of the "old" kotlin code generation.

But I have one problem :)

Currently, what I am doing to call my GQL APIs is the following:

val graphQLQueryRequest = GraphQLQueryRequest(
    query = CoursesGraphQLQuery.Builder()
        .build(),
    projection = CoursesProjectionRoot()
        .items().id(),
    scalars = scalars
)

With scalar being a mapOf(UUID::class.java to graphql.scalars.id.UUIDScalar.INSTANCE.coercing) and this works like charm.

What I would like to do, by leveraging kotlin2 implementation, is:

DgsClient.buildQuery {
    course(id = UUID.randomUUID()) {
        id // this is a UUID as well
    }
}

but when I try to do this, I get this error:

java.lang.NoSuchMethodError: 'graphql.language.Value com.netflix.graphql.dgs.client.codegen.InputValueSerializer.toValue(java.lang.Object)'

	at com.netflix.graphql.dgs.codegen.GraphQLProjection.arguments(Kotlin2Core.kt:108)
	at com.netflix.graphql.dgs.codegen.GraphQLProjection.field(Kotlin2Core.kt:138)
        TRUNCATED BY ME

If I try it without the input parameter, it works fine, that means that somehow the return parameter is able to deserialize a UUID to String.

Digging a little bit inside the kotlin2 implementation, I see that in the Kotlin2Core.kt class there is this private val inputSerializer = InputValueSerializer() instantiated in the companion object that can actually be instantiated with a custom map of scalars, but it's impossible to reach from the outside. I have no control over it.

My question is: would it be possible to make code generation for kotlin2 to create the code to pass a custom map of scalars as I do for the GraphQLQueryRequest in the first example? Maybe there is a way of doing it that I am not seeing?

Thanks a lot for your hard work!!

@l3r8yJ
Copy link

l3r8yJ commented Nov 14, 2023

I had the same problem, would like to send a pr to fix this problem

@dwilkolek
Copy link
Contributor

Same problem brought be here. I just copied GraphQLProjection class into com.netflix.graphql.dgs.codegen package in my sources to override it but it's not a sustainable solution.

I peeked into your PR and I think it won't be convenient. Typically in app runtime you define scalars once for the whole application. Imagine having deep and nested projection - passing scalars map to each projection would be annoying. 😅 Maybe that approach would be more welcome.

dwilkolek added a commit to dwilkolek/dgs-codegen that referenced this issue Apr 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants