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
feature: Allow specifying custom scalars when generating queries using Kotlin query projections #1860
Comments
That should be supported, unless you're thinking of something different than what we have... Check out this integration test example: There are a couple of custom scalars in there, mapped with the same configuration as the normal codegen stuff. This is where it gets wired up for these tests: In gradle, the same config would look something like this:
This was the type mapping setup that the codegen stuff was using when I made this kotlin version. It looks like that there's a new way of passing this mapping in code that we don't support in the new DSL. Let me know if the configuration mapping won't work for you & I can take another look. |
Hi @mbossenbroek, Thanks for a prompt response. It seems I didn't make myself clear enough, sorry. The problem I'm experiencing is not related to the code generation itself, that actually works fine. But it is related to the type mapping. Let me explain. ContextWe have the codegen configured with type mapping like so: typeMapping =
mutableMapOf(
"ISO8601Date" to "java.time.LocalDate",
"UUID" to "java.util.UUID",
"ID" to "com.productboard.common.graphql.id.GraphqlId"
) where the class we map the data class GraphqlId(val type: String, val id: String) This correctly generates Kotlin classes where the We then use something like this @DgsScalar(name = "ID")
class GraphQlIdScalar : Coercing<GraphqlId, String> {
// implementation here
} to plug the custom type into the framework. So far so good. The problemHowever, when I try actually generating a query using a projection with input arguments containing this custom type, it doesn't validate. Each
This is apparently because the projection doesn't know it should serialize this type using the corresponding While this seems to be supported in the "old" API via the option to pass explicit Having checked the code, it looks like when generating the query string, the program reaches this point where it tries to serialize the value. However, the This is different from the aforementioned Note that in my case, this manifests in tests where I'm using the projection of a query with input arguments to generate a query string which then gets executed. Hope this make it clearer. I see how my original post could have easily been misunderstood, sorry about that 🙂 |
Gotcha - that makes more sense. I'll take a deeper look at this, but it should be doable. That said, I might not get to it for a few weeks, and as always - feel free to drop a PR with the change :) |
I'll do my best to have a look 🙃 I just think it won't be exactly trivial to implement for someone with zero knowledge of the codegen internals such as myself. I suspect this will require changes to the code generation itself to make the option available on the |
Yeah, that's totally fair. If you're really interested and/or need it sooner, I'd be happy to jump on a VC & walk you through it, but also totally understand if not & just want to wait a couple weeks |
This is by no means a blocker for us, so I'm more than happy to wait 🙃 Thanks for being so helpful though 👍 |
Hey @dmoidl , I was just about to do this today & somebody else dropped this PR, which I believe will satisfy your need, right? Lmk if you think this will work or not... Netflix/dgs-codegen#675 |
This is released now |
Thank @mbossenbroek for letting me know 🙂 I think this will do just fine. However, I believe it's not yet released, is it? 🤔 The latest available version seems to be No worries though, I'll wait until it makes it to a released version. |
Ahh apologies - I changed the original PR a bit in this PR: https://github.com/Netflix/dgs-codegen/pull/677/files#diff-39435f9dc1a43ff8f5570174fdbd1d26970cc2fe5b3b94c22f43e06f403bd8b0 The old way used a thread local to pass in a custom serializer; the new way generates the projections such that they take an optional parameter that's an In any case, lmk if that doesn't make sense & I'll reinstate an example/test for you. |
Describe the Feature Request
When using the new Kotlin Query projections, it is currently impossible to use custom scalar configuration when constructing the query.
Using custom scalars is available when using the GraphQLQueryRequest API, so this looks like a missing feature in the new API.
I understand that the new Kotlin codegen is still experimental, but having checked the code, I found there is currently no way to possibly achieve this, hence this feature request.
Describe Preferred Solution
It would be ideal if we could provide custom scalar implementations to the new query projections in a similar fashion it is currently done for
GraphQLQueryRequest
.Describe Alternatives
I can imagine being able to register custom scalar implementations in a different way, possibly on the client level or such. But the only other alternative seems to be the current scenario where this is not possible at all.
The text was updated successfully, but these errors were encountered: