TypeScript GraphQL Files Modules
GraphQL Code Generator plugin for generating TypeScript types for GraphQL files. This plugin generates a single file per GraphQL file, and uses the `graphql-tag/loader` to load the GraphQL files.
- Version
- 5.0.0
- Weekly downloads
- 101k
- License
- MIT
- Updated
- Nov 11, 2026
Installation
npm i -D @graphql-codegen/typescript-graphql-files-modules
yarn add -D @graphql-codegen/typescript-graphql-files-modules
pnpm add -D @graphql-codegen/typescript-graphql-files-modules
bun add -D @graphql-codegen/typescript-graphql-files-modules
Config API Reference
modulePathPrefix
type: string
Allows specifying a module definition path prefix to provide distinction between generated types. Default value: ""
Usage Examples
import type { CodegenConfig } from '@graphql-codegen/cli';
const config: CodegenConfig = {
// ...
generates: {
'src/api/user-service/queries.d.ts': {
documents: 'src/api/user-service/queries.graphql',
plugins: ['typescript-graphql-files-modules'],
config: {
// resulting module definition path glob: "*\/api/user-service/queries.graphql"
modulePathPrefix: "/api/user-service/",
},
},
},
};
export default config;
relativeToCwd
type: boolean
By default, only the filename is being used to generate TS module declarations. Setting this to true will generate it with a full path based on the CWD.
Default value: “false”
prefix
type: string
By default, a wildcard is being added as prefix, you can change that to a custom prefix Default value: ”*/”
type
type: string
By default, the named exports will have a type DocumentNode. Change this to “string” if you only use raw strings.
Default value: “DocumentNode”
Pre-Requirements
To use this template, make sure you are using
graphql-tag/loader
with Webpack.
Example
Given that you have a query named MyQuery in my-query.graphql file, this template will generate
the following code:
Accordingly, you can import the generated types and use it in your code:
OR