UNPKG

@graphql-codegen/typescript-document-nodes

Version:

GraphQL Code Generator plugin for generating TypeScript modules with embedded GraphQL document nodes

159 lines (158 loc) 5.08 kB
import { PluginFunction, PluginValidateFn } from '@graphql-codegen/plugin-helpers'; import { NamingConvention, RawClientSideBasePluginConfig } from '@graphql-codegen/visitor-plugin-common'; /** * @description This plugin generates TypeScript source `.ts` file from GraphQL files `.graphql`. */ export interface TypeScriptDocumentNodesRawPluginConfig extends RawClientSideBasePluginConfig { /** * @default change-case-all#pascalCase * @description Allow you to override the naming convention of the output. * You can either override all namings, or specify an object with specific custom naming convention per output. * The format of the converter must be a valid `module#method`. * Allowed values for specific output are: `typeNames`, `enumValues`. * You can also use "keep" to keep all GraphQL names as-is. * Additionally, you can set `transformUnderscore` to `true` if you want to override the default behavior, * which is to preserve underscores. * * Available case functions in `change-case-all` are `camelCase`, `capitalCase`, `constantCase`, `dotCase`, `headerCase`, `noCase`, `paramCase`, `pascalCase`, `pathCase`, `sentenceCase`, `snakeCase`, `lowerCase`, `localeLowerCase`, `lowerCaseFirst`, `spongeCase`, `titleCase`, `upperCase`, `localeUpperCase` and `upperCaseFirst` * [See more](https://github.com/btxtiger/change-case-all) * * @exampleMarkdown * ## Override All Names * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'path/to/file': { * // plugins... * config: { * namingConvention: 'change-case-all#lowerCase', * }, * }, * }, * }; * export default config; * ``` * * ## Upper-case enum values * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'path/to/file': { * // plugins... * config: { * namingConvention: { * typeNames: 'change-case-all#pascalCase', * enumValues: 'change-case-all#upperCase', * } * }, * }, * }, * }; * export default config; * ``` * * ## Keep names as is * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'path/to/file': { * // plugins... * config: { * namingConvention: 'keep', * }, * }, * }, * }; * export default config; * ``` * * ## Remove Underscores * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'path/to/file': { * // plugins... * config: { * namingConvention: { * typeNames: 'change-case-all#pascalCase', * transformUnderscore: true * } * }, * }, * }, * }; * export default config; * ``` */ namingConvention?: NamingConvention; /** * @default "" * @description Adds prefix to the name * * @exampleMarkdown * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'src/api/user-service/queries.ts': { * plugins: ['typescript-document-nodes'], * config: { * namePrefix: 'gql', * }, * }, * }, * }; * export default config; * ``` */ namePrefix?: string; /** * @default "" * @description Adds suffix to the name * * @exampleMarkdown * ```ts filename="codegen.ts" * import type { CodegenConfig } from '@graphql-codegen/cli'; * * const config: CodegenConfig = { * // ... * generates: { * 'src/api/user-service/queries.ts': { * plugins: ['typescript-document-nodes'], * config: { * nameSuffix: 'Query' * }, * }, * }, * }; * export default config; * ``` */ nameSuffix?: string; /** * @default "" * @description Adds prefix to the fragment variable */ fragmentPrefix?: string; /** * @default "" * @description Adds suffix to the fragment variable */ fragmentSuffix?: string; } export declare const plugin: PluginFunction<TypeScriptDocumentNodesRawPluginConfig>; export declare const validate: PluginValidateFn<any>;