GraphQL Modules Preset
GraphQL Code Generator preset for graphql-modules. It generates a single file with all the modules and their dependencies.
- Version
- 6.1.0
- Weekly downloads
- 40k
- License
- MIT
- Updated
- Jul 6, 2026
Installation
npm i -D @graphql-codegen/graphql-modules-preset
yarn add -D @graphql-codegen/graphql-modules-preset
pnpm add -D @graphql-codegen/graphql-modules-preset
bun add -D @graphql-codegen/graphql-modules-preset
Config API Reference
baseTypesPath
type: string
Required, should point to the base schema types file. The key of the output is used a base path for this file.
importBaseTypesFrom
type: string
Overrides the package import for the base types. Use this if you are within a monorepo, and you wish to import the base types directly from a different package, and not from a relative path.
cwd
type: string
Optional, override the cwd of the execution. We are using cwd to figure out the imports between files. Use this if your execution path is not your project root directory.
Default value: “process.cwd()“
importTypesNamespace
type: string
Optional, override the name of the import namespace used to import from the baseTypesPath file.
Default value: “Types”
filename
type: string
Required, sets the file name for the generated files.
encapsulateModuleTypes
type: string
Configure how to encapsulate the module types, to avoid confusion.
namespace (default): will wrap all types in a TypeScript namespace, using the module name.
prefix: will prefix all types from a specific module with the module name.
none: will skip encapsulation, and generate type as-is.
Default value: “namespace”
requireRootResolvers
type: boolean
Generate resolvers of root types (Query, Mutation and Subscription) as non-optional. Default value: “false”
useGraphQLModules
type: boolean
By default, the generated types will generate some code specific to graphql-modules library.
If you are not using GraphQL-Modules, you can disable this feature by setting this to false.
Default value: “true”
The @graphql-codegen/graphql-modules-preset generates .ts file with TypeScript types, per each
directory that contains GraphQL SDL definitions.
The generates files will be generated based on each module definition, and based on the GraphQL schema defined in that specific module, allowing you to write type-safe resolvers, while keeping modules types boundaries.
Usage Example
Given a folder structure with the following files:
Here’s a short example for generating types and resolvers for 2 modules:
This will generate a file called module-types.ts under each module you have.
To use the generates resolvers, you can use Resolvers signature and apply it to your resolvers
object within the module:
Using without GraphQL-Modules
By default, this preset it generating code for graphql-modules, but if you are not using it, you
can set useGraphQLModules: false{:yaml} in your preset configuration to generate fully agnostic
types that are based on folder structure only.