Kotlin2 codegen implementation is eager
Nobody has claimed this yet.
- Dominant language
- Kotlin
- Stars
- 217
- Forks
- 116
- PR merge metrics
- No merged PRs in 30d
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The payload names GraphQLQueryRequest, DgsClient.buildQuery, and the Kotlin2 projection implementation as relevant entry points; start by tracing how projections are generated and serialized in these paths. Compare the Java field-map behavior with Kotlin2, then verify that repeated selected fields are deduplicated while preserving the Query/Projection split.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, kotlin
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100