Back to Graphql Code Generator

`config` field

website/src/pages/docs/config-reference/config-field.mdx

1.17.71.5 KB
Original Source

import { Callout } from '@theguild/components'

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:

ts
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:

ts
import { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  schema: 'schema.graphql',
  generates: {
    'output.ts': {
      config: {
        configKey: 'configValue'
      },
      plugins: ['plugin1', 'plugin2']
    }
  }
}
export default config

<Callout>Output level configuration overrides root-level configuration.</Callout>

Plugin Level

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

ts
import { CodegenConfig } from '@graphql-codegen/cli'

const config: CodegenConfig = {
  schema: 'schema.graphql',
  generates: {
    'output.ts': [
      {
        plugin1: { configKey: 'configValue' }
      },
      {
        plugin2: { configKey: 'otherValue' }
      }
    ]
  }
}
export default config

<Callout>Plugin level configuration overrides output-level and root-level configuration.</Callout>