# Config options Every documented config option of a plugin has a generated example: a minimal schema, a minimal operation, and the TypeScript each value of the option produces. Examples are generated by running the plugin. Never write example output by hand. ## When to use this - You add a config option to a plugin. - You change what an existing option generates, or its JSDoc. - You need to show an option's output (in docs, an issue or a PR description). ## Adding a config option 1. **Declare it** in the plugin's config interface (e.g. `packages/plugins/typescript/operations/src/config.ts`), with JSDoc: - `@description`: what the option does. - `@default`: the value used when the option is left out. Skip it when there is none. - `@exampleMarkdown`: a `codegen.ts` snippet that sets the option, following the other options in the file. Don't paste generated output here; the example spec produces it. ````ts /** * @description Adds `readonly` to every generated field. * @default false * * @exampleMarkdown * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'path/to/file.ts': { * plugins: ['typescript-operations'], * config: { * myOption: true * }, * }, * }, * }; * export default config; * ``` */ myOption?: boolean; ```` 2. **Implement it** and add tests for it in the plugin's own `tests/` folder. 3. **Regenerate the docs schema**, so the option is documented: ```bash pnpm --filter website generate-config-schema ``` 4. **Add an example** to `packages/utils/config-examples/src/.spec.ts` (see "Adding or updating an example" below), then regenerate the examples and the docs schema again. 5. **Add a changeset** for the plugin (`pnpm changeset`). The examples package is private and needs none. 6. **Commit** the config change, the example spec, the option's generated example file and `website/config.schema.json` together. ## Adding or updating an example Add a `ConfigExample` to the `examples` list in `src/.spec.ts`, in the order the options appear in `config.ts`: ```ts { option: 'myOption', schema: /* GraphQL */ ` type Query { user: User } type User { id: ID! } `, operation: /* GraphQL */ ` query GetUser { user { id } } `, variants: [{ myOption: false }, { myOption: true }], }, ``` - `schema` and `operation`: the smallest schema and operation that show the option's effect, written in the example itself. - `variants`: one config per value or form the option accepts (e.g. `true` and the object form). Each option has one example: put every form in its variants. When the option needs another option to have an effect, put that option in every variant too (e.g. `{ enumType: 'native', enumValues: … }`). The **first** variant is the default: spell the default value out (`{ myOption: false }`), or leave the option out when it has no default. The test fails if the first variant's output differs from the same config without the option. - `note`: only when the output alone would mislead, e.g. the option only works together with another option, or has no effect. Then: 1. Regenerate the examples: ```bash pnpm vitest run packages/utils/config-examples -u ``` 2. Read the option's file, `src/__examples__//