Netflix / Netflix/dgs-codegen

Kotlin2 codegen implementation is eager

Open
#428 3 comments 0 reactions 0 assignees View on GitHub

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.