Netflix / Netflix/dgs-codegen

Java codegen: generate sealed interface for GraphQL interfaces/unions and record for implementing types

Open
#923 0 comments 0 reactions 1 assignee View on GitHub

@jiholee17 is already working on this.

Since Apr 6, 2026.

enhancement
Dominant language
Kotlin
Stars
217
Forks
116
PR merge metrics
No merged PRs in 30d

Description

The Kotlin2 codegen already generates sealed interface for GraphQL interfaces and unions. The Java path still generates plain interface + mutable POJOs.

It'd be nice if you generated sealed interfaces in Java too, since that's the closest match to what is expressed in GQL by an interface or union.

Concrete example from our schema:

 interface INKSIGHT_OcrJob { ... }                                                                                                         
 type INKSIGHT_OcrJobCompleted implements INKSIGHT_OcrJob { corpusUrl: BagginsUrl! }                                                                                
 type INKSIGHT_OcrJobPending implements INKSIGHT_OcrJob { }                                                                                             
 type INKSIGHT_OcrJobFailed implements INKSIGHT_OcrJob { message: String! }                                                                                     
                                                                                                                           
 Today this generates a plain interface + 3 mutable POJOs. What we want:                                                                                      
                                  
 public sealed interface INKSIGHT_OcrJob                                                                                                      
   permits INKSIGHT_OcrJobCompleted, INKSIGHT_OcrJobPending, INKSIGHT_OcrJobFailed { ... }
 public record INKSIGHT_OcrJobCompleted(...) implements INKSIGHT_OcrJob { }                                                                                     
 // etc. 

That would give us exhaustive switch in Java 21+, immutability by default, and the compiler enforcing what the schema already guarantees.

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.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.