diff --git a/docs/content/1.getting-started/4.configuration.md b/docs/content/1.getting-started/4.configuration.md index 2309b4f..3556855 100644 --- a/docs/content/1.getting-started/4.configuration.md +++ b/docs/content/1.getting-started/4.configuration.md @@ -71,7 +71,8 @@ export default defineNuxtConfig({ dedupeFragments: true, onlyOperationTypes: true, avoidOptionals: false, - disableOnBuild: false + disableOnBuild: false, + maybeValue: 'T | null' } } }) @@ -121,6 +122,12 @@ Avoid using TypeScript optionals on types. See [GraphQL Code Generator documenta Disable Code Generation for production builds. +### `maybeValue` + + - default: `"T | null"` + +Allow to override the type value of `Maybe`. See [GraphQL Code Generator documentation](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations#maybevalue) for more options + ## Client configuration ::alert{type="warning"} diff --git a/src/generate.ts b/src/generate.ts index fc36653..5266ce7 100644 --- a/src/generate.ts +++ b/src/generate.ts @@ -49,7 +49,8 @@ function prepareConfig (options: GenerateOptions & GqlCodegen): CodegenConfig { namingConvention: { enumValues: 'change-case-all#upperCaseFirst' }, - avoidOptionals: options?.avoidOptionals + avoidOptionals: options?.avoidOptionals, + maybeValue: options?.maybeValue } const generates: CodegenConfig['generates'] = Object.entries(options.clients || {}).reduce((acc, [k, v]) => { diff --git a/src/module.ts b/src/module.ts index 46493e1..72cfb5e 100644 --- a/src/module.ts +++ b/src/module.ts @@ -49,7 +49,8 @@ export default defineNuxtModule({ dedupeFragments: true, disableOnBuild: false, onlyOperationTypes: true, - avoidOptionals: false + avoidOptionals: false, + maybeValue: 'T | null' } config.codegen = !!config.codegen && defu(config.codegen, codegenDefaults) diff --git a/src/types.d.ts b/src/types.d.ts index 4a25d4b..fbf9600 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -91,7 +91,7 @@ export interface GqlClient { /** * Headers to be passed from the browser to the GraphQL API in SSR mode. - * + * * @type {string[]} */ proxyHeaders?: string[] @@ -190,6 +190,12 @@ export interface GqlCodegen { object?: boolean defaultValue?: boolean } + + /** + * Allow to override the type value of Maybe. + (https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations#maybevalue) + */ + maybeValue?: string } export interface GqlConfig {