Presets
import-types

Import Types Preset

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/import-types-presetDownloadsVersionLicenseSep 25th, 2023

Installation

npm i -D @graphql-codegen/import-types-preset

Config API Reference

typesPath

type: string

Required, should point to the base schema types file. The key of the output is used a the base path for this file.

Usage Examples

codegen.ts
 import type { CodegenConfig } from '@graphql-codegen/cli';
 
 const config: CodegenConfig = {
   // ...
   generates: {
     'path/to/file.ts': {
       preset: 'import-types',
       plugins: ['typescript-operations'],
       presetConfig: {
         typesPath: 'types.ts'
       },
     },
   },
 };
 export default config;

importTypesNamespace

type: string default: Types

Optional, override the name of the import namespace used to import from the baseTypesPath file.

Usage Examples

codegen.ts
 import type { CodegenConfig } from '@graphql-codegen/cli';
 
 const config: CodegenConfig = {
   // ...
   generates: {
     'path/to/file.ts': {
       preset: 'import-types',
       plugins: ['typescript-operations'],
       presetConfig: {
         typesPath: 'types.ts',
         importTypesNamespace: 'SchemaTypes',
       },
     },
   },
 };
 export default config;

This preset generates a file per each operation file, and allow to import types from another file.