other
add

Add

Package nameWeekly DownloadsVersionLicenseUpdated
@graphql-codegen/add (opens in a new tab)DownloadsVersionLicenseFeb 5th, 2023

Installation

Terminal
yarn add -D @graphql-codegen/add

add plugin adds custom text to your output file.

You can use this plugin to add custom code, imports, comments and more to your output file.

Examples

codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  // ...
  generates: {
    'path/to/file.ts': {
      plugins: [
        {
          add: {
            content: '/* eslint-disable */'
          }
        },
        'typescript'
      ]
    }
  }
}
export default config
codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli'
 
const config: CodegenConfig = {
  // ...
  generates: {
    'path/to/file.ts': {
      plugins: [
        {
          add: {
            content: ['declare namespace GraphQL {']
          }
        },
        {
          add: {
            placement: 'append',
            content: '}'
          }
        },
        'typescript'
      ]
    }
  }
}
export default config

Config API Reference

placement

type: string (values: append, content, prepend) default: prepend

Allow you to choose where to add the content.

content

type: string[] | string

The actual content you wish to add, either a string or array of strings. You can also specify a path to a local file and the content if it will be loaded by codegen.