Skip to main content
Drupal is a registered trademark of Dries Buytaert
EOL Warning: Drupal 11.0 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.3 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.2 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.1 has reached end of life and no longer receives security updates. EOL Warning: Drupal 10.0 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.5 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.4 has reached end of life and no longer receives security updates. EOL Warning: Drupal 9.3 has reached end of life and no longer receives security updates. Release: Raven: Sentry Integration 7.5.2 Minor update available for module raven (7.5.2). Usage Milestone: jQuery UI Datepicker Module jquery_ui_datepicker crossed 1,000 active installs.

GraphQL Compose Codegen

5 sites No security coverage Drupal 10–11 Graphql ecosystem
View on drupal.org

This module automatically generates TypeScript types, GraphQL fragments, and React component stubs for your decoupled frontend from your Drupal content model. It helps keep your frontend in sync with your backend by generating code for your headless Drupal setup.

GraphQL Compose Codegen generates TypeScript types, GraphQL fragments, and React component stubs for Next.js frontends from your Drupal content model, so the frontend stays in sync with the schema.

This module is for Drupal sites that serve content to a separate frontend application — often called a "headless" or "decoupled" setup. If you're using the GraphQL Compose module to expose your content as a GraphQL API, this module handles the tedious next step: writing the TypeScript types and GraphQL queries the frontend needs to consume that data. When you add a content type, paragraph type, or field in Drupal, the module tells you exactly what to regenerate and produces ready-to-merge code so you don't write boilerplate by hand.

Features

The module adds four Drush commands and a set of admin integrations:

  • drush gqcc:inspect — lists every node and paragraph bundle and the "extra" fields it adds beyond your shared base type, with their resolved TypeScript types.
  • drush gqcc:generate — writes four scaffold artefacts per run: TypeScript type definitions, GraphQL inline fragments, a NodeRenderer switch-case file, and one React component stub per bundle.
  • drush gqcc:diff — compares the current schema against the last generation, so you can see what changed before regenerating.
  • drush gqcc:validate — verifies that the scaffold files on disk are in sync with the live schema. Exits non-zero, so it's safe to wire into CI or a pre-commit hook.
  • Schema-change notices — when someone adds or removes a content type, paragraph type, or field via the Drupal admin UI, the module logs a notice at /admin/reports/dblog with the exact command to run.
  • Full paragraph support — paragraph bundles produce their own type definitions, fragments, and component stubs alongside node bundles.
  • Pluggable field-type mappers — other modules can register their own Drupal-field-type → TypeScript-type mappings via tagged plugins, so custom field types can be handled without patching this module.
  • --dry-run, --allow-external, idempotent writes (no churn when nothing changed), and an output-dir safety guard that prevents accidental writes to dangerous filesystem locations.

Typical use cases:

  • You maintain a Drupal site with a Next.js frontend (on next-drupal or a hand-rolled GraphQL client) and keep losing time hand-typing TypeScript shapes for every new field.
  • Your editorial team adds content types and you want a single command that scaffolds the matching frontend files instead of doing it from memory.
  • You want CI to fail when somebody forgets to regenerate types after a content-model change.

Post-Installation

  1. Install with Composer and enable the module:

    composer require drupal/graphql_compose_codegen
    drush en graphql_compose_codegen
  2. Visit Configuration → Development → GraphQL Compose Codegen (or /admin/config/development/graphql-compose-codegen) to set:

    • The name of your shared base TypeScript type (default NodeCommonFields)
    • The list of fields that already live in that shared base type, which are excluded from per-bundle output
    • A default output directory for generated files (relative to the Drupal root or absolute)

    The same values can also be set via drush config:set or by editing graphql_compose_codegen.settings.yml in your config sync directory.

  3. From the command line, point the generator at your Next.js project root:

    drush gqcc:generate --output-dir=../ui

    The four scaffold artefacts land under {output-dir}/generated/. Review each file, then merge the pieces you need into your types/index.d.ts, your node-by-path query, your NodeRenderer.tsx, and your components/drupal/ directory. The generated files have a .generated suffix and are intentionally not referenced anywhere — delete them once you've integrated what you need.

  4. Check /admin/reports/status for runtime checks (whether any node bundles exist, whether your configured base type fields actually exist on at least one bundle).
  5. Check /admin/help/graphql_compose_codegen for a quick reference to the four commands.

Additional Requirements

  • Drupal core 10.6, or 11.3+
  • PHP 8.1 or higher
  • GraphQL Compose 2.1 or higher (this module introspects its schema)
  • Drush 12 or 13 — Drush is a hard dependency because the module's entire user surface is Drush commands

These modules aren't required, but if they're enabled their field types are mapped automatically:

  • Paragraphs — enables paragraph-bundle introspection and fragment generation
  • Schedulerpublish_on / unpublish_on fields are mapped to TypeScript string
  • Smart Datesmartdate fields are mapped to a SmartDate TypeScript type

Custom field types from any other module can be supported by writing a small FieldTypeMapper plugin. See graphql_compose_codegen.api.php for the hook and plugin documentation.

Similar projects

Several modules touch adjacent problems. None of them produce the same output for the same stack:

  • TypeScript Definition Generator generates TypeScript types for Drupal's internal entity API (e.g. FieldItemList<IntegerItem>). This module generates the client-facing shape that GraphQL Compose actually returns over the wire.
  • Next.js generator scaffolds Next.js components from JSON:API using the Drush Code Generator. This module is opinionated for GraphQL Compose instead, and produces TypeScript types and fragments alongside React components.
  • GraphQL Compose: Fragments auto-generates GraphQL fragments and exposes them server-side in the schema's _info query. This module writes fragments to disk so you can paste them directly into hand-written queries, and also produces TypeScript types and React stubs.
  • GraphQL Export exports the raw .graphqls schema or introspection JSON to disk for use with the npm graphql-codegen tool. The two are complementary — this module is opinionated about the GraphQL Compose + Next.js + React stack and emits ready-to-merge code, not raw schema.

This module is intentionally narrow in scope. If you're on a different decoupled stack (Vue, Svelte, Astro, JSON:API), one of the modules above will serve you better.

Supporting this Module

Bug reports, feature requests, and merge requests are welcome in the issue queue. Patches that add field-type mappers for popular contrib modules are especially appreciated.

Community Documentation

(None yet — links to walkthroughs, blog posts, and demo sites will be added here as they're published.)

Depends on

Dependencies of the latest stable release

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
7
Tracked since
May 2026
Latest release
2 days ago
Releases (12 mo)
7 ▲ from 0
Maintenance
Active

Release Timeline

Releases

Version Type Core Release date
1.1.1 Stable 10–11 Aug 25, 2026
1.1.0 Stable 10–11 Jul 25, 2026
1.x-dev Dev 10–11 Jul 23, 2026
1.0.0 Stable 10–11 Jul 23, 2026
1.0.0-rc1 Pre-release 10–11 Jul 22, 2026
1.0.0-alpha2 Pre-release 10–11 May 29, 2026
1.0.x-dev Dev 10–11 May 29, 2026