dgs-codegen
dgs-codegen copied to clipboard
Kotlin2 codegen implementation is eager
Hey all,
Thanks for this amazing library. In our current setup I ran into the following. When building the query with Kotlin projections (love the feature) it's eager. When you select a field or create a projection, the string is build eagerly.
Compared to the Java implementation the fields are stored to a map and serialised when you call the .serialize()
function. The result is, when you are selecting the same field multiple times it's only included once.
We try to split our projection selection which might result in duplication of selecting a field (for example a name
or id
property) and this is now included in the query. GraphQL does accept it but it adds extra noise to the query which is not needed.
Proposed solution
Instead of moving to the DgsClient.buildQuery
still support the split between Query
and Projection
which is done by using the GraphQLQueryRequest
. This then can use the same underlying builder pattern that is now for the Projections but instead of calling functions it's done with the same solution that is being used for the Kotlin2 implementation.
Example
Current java result
public XProjectionRoot y() {
getFields().put("y", null);
return this;
}
Current kotlin2 implementation
public val y: XProjection
get() {
field("y")
return this
}
Proposed kotlin2 implementation
public val y: XProjection
get() {
getFields().put("y", null);
return this
}
And instead of using the DgsClient.buildQuery
function we can provide the projection to the current GraphQLQueryRequest
cc @mbossenbroek
I made a change recently to use the GQL builders instead of constructing strings: https://github.com/Netflix/dgs-codegen/pull/423/commits/3778f55bc0cb147b66eec2ddc1bf07a7b8b18296
It was over a month ago, so that should have been released by now - can you confirm you're on that version?
I'm not sure I understand the issue you're having either - do you have a simple example with the behavior that's undesirable?
Just noticed you posted this a few days before I made that commit - give that a try & let me know. Also feel free to tag me directly in the future for any kotlin2 questions