config field

The config field is used to pass configuration to Plugins.

config can be specified at many levels of the configuration:

Root Level

If you specify it in your root level, the options will be passed to every plugin for each output file:

import { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  schema: 'schema.graphql',
  config: { configKey: 'configValue' },
  generates: { 'output.ts': ['plugin1', 'plugin2'] }
}
export default config

Output Level

If you specify it at the output file level, every plugin for specific output will get the config value:

import { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  schema: 'schema.graphql',
  generates: {
    'output.ts': {
      config: {
        configKey: 'configValue'
      },
      plugins: ['plugin1', 'plugin2']
    }
  }
}
export default config
💡
Output level configuration overrides root-level configuration.

Plugin Level

If you specify it at the plugin level, only that plugin will get the config value:

import { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  schema: 'schema.graphql',
  generates: {
    'output.ts': [
      {
        plugin1: { configKey: 'configValue' }
      },
      {
        plugin2: { configKey: 'otherValue' }
      }
    ]
  }
}
export default config
💡
Plugin level configuration overrides output-level and root-level configuration.