Netflix / Netflix/dgs-codegen

Support `custom root type names` in schema (e.g. query_root instead of Query)

Open
#849 1 comment 1 reaction 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

Hi DGS team 👋

We’re currently using DGS Codegen to generate Java client code from a GraphQL schema that is generated by Hasura.

Hasura generates a valid GraphQL schema with custom root type names, such as query_root, mutation_root, and subscription_root, instead of the usual Query, Mutation, and Subscription.

Example schema:

schema {
  query: query_root
  mutation: mutation_root
  subscription: subscription_root
}

type query_root {
  # some fields here
}

type mutation_root {
  # some fields here
}

type subscription_root {
  # some fields here
}

While this is perfectly valid according to the GraphQL spec (see GraphQL spec 3.2), it seems that DGS Codegen relies on the root types being named Query, Mutation, and Subscription, and does not generate code for these custom root types.

Our current workaround

As a workaround, we manually rewrite the schema before passing it to DGS Codegen:

schema {
  query: Query
  mutation: Mutation
  subscription: Subscription
}

# then copy contents from query_root to Query, etc.

This allows client code generation to work properly, but it’s a manual.

Feature request

Would it be possible for DGS Codegen to allow users to configure the names of the root types (query, mutation, subscription) via codegen config ?

Motivation

This would improve compatibility with Hasura and any other GraphQL server that uses valid non-standard root type names, without requiring manual schema rewriting.

Sources

https://github.com/deweyjose/graphqlcodegen/issues/245#issuecomment-2944055960

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

Start by locating the codegen configuration and the schema-processing entry point that discovers query, mutation, and subscription root types. Reproduce the issue with the Hasura-style schema shown here; done means configurable custom root names generate client code without manually rewriting the schema.

Written by the indexing model from the issue text.

Assessment

Tech stack
kotlin
Domain
tooling
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
58/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.