Skip to content

Commit

Permalink
feat: add maybeValue option on codegen options (#405)
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzofaresin authored and lfaresin-dmind committed Oct 27, 2023
1 parent 89ae212 commit 3a70a7f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
9 changes: 8 additions & 1 deletion docs/content/1.getting-started/4.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ export default defineNuxtConfig({
dedupeFragments: true,
onlyOperationTypes: true,
avoidOptionals: false,
disableOnBuild: false
disableOnBuild: false,
maybeValue: 'T | null'
}
}
})
Expand Down Expand Up @@ -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"}
Expand Down
3 changes: 2 additions & 1 deletion src/generate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]) => {
Expand Down
3 changes: 2 additions & 1 deletion src/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ export default defineNuxtModule<GqlConfig>({
dedupeFragments: true,
disableOnBuild: false,
onlyOperationTypes: true,
avoidOptionals: false
avoidOptionals: false,
maybeValue: 'T | null'
}

config.codegen = !!config.codegen && defu<GqlCodegen, [GqlCodegen]>(config.codegen, codegenDefaults)
Expand Down
8 changes: 7 additions & 1 deletion src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export interface GqlClient<T = string> {

/**
* Headers to be passed from the browser to the GraphQL API in SSR mode.
*
*
* @type {string[]}
*/
proxyHeaders?: string[]
Expand Down Expand Up @@ -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<T = GqlClient> {
Expand Down

0 comments on commit 3a70a7f

Please sign in to comment.