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

Aperta
#923 0 commenti 0 reazioni 1 assegnatario Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@jiholee17 ci sta già lavorando.

Dal 6/4/2026.

Valutazione

Questa issue non è ancora stata valutata.

Descrizione

enhancement

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.

Lingua principale
Kotlin
Stelle
220
Fork
123
Merge medio
1g 6h
PR unite (30g)
23

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di Netflix/dgs-codegen

Tutte le issue di Netflix/dgs-codegen

Issue simili

Altre issue su Kotlin

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.