Netflix / Netflix/dgs-codegen

Unable to generate projection for an interface

Open
#855 1 comment 2 reactions 1 assignee View on GitHub

@paulbakker is already working on this.

Since Aug 11, 2025.

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

Description

If we take this as the graph where one interface implements/extends another interface, and generate client code:

type Query {
    profile: Profile
}

type Profile {
    id: ID!
    agreements: [Agreement!]!
}

interface Agreement {
    id: ID!
}

interface Account implements Agreement {
    id: ID!
    name: String!
    balance: Float!
}

type PaymentAccount implements Agreement & Account {
    id: ID!
    name: String!
    balance: Float!
    currency: String!
}

type SavingsAccount implements Agreement & Account {
    id: ID!
    name: String!
    balance: Float!
    interestRate: Float!
}

...then I can generate a request as follows:

val projection = ProfileProjectionRoot<Nothing, Nothing>()
    .id()
    .agreements()
    .onPaymentAccount().balance().id().name()
    .parent()
    .onSavingsAccount().balance().id().name()
    .root()

val query = ProfileGraphQLQuery.Builder().build()
val request = GraphQLQueryRequest(query, projection)

Which generates a query like this:

{
  profile {
    id
    agreements {
      ... on PaymentAccount {
        __typename
        balance
        id
        name
      }
      ... on SavingsAccount {
        __typename
        balance
        id
        name
      }
    }
  }
}

However, this would also be a valid query:

{
  profile {
    id
    agreements {
      ... on Account {
        __typename
        balance
        id
        name
      }
    }
  }
}

But the code generation doesn't allow code like this:

val projection = ProfileProjectionRoot<Nothing, Nothing>()
    .id()
    .agreements()
    .onAccount().balance().id().name() // onAccount doesn't exist
    .root()

However, a tool like GraphiQL does give this option:

Image

Would this be possible to do with the current codegen, or would it be possible to add such an option?

I created an example in https://github.com/martinvisser/dgs-codegen-interfaces to show my idea.

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.