Skip to content

Commit

Permalink
feat: expose the codegen scalars (#567)
Browse files Browse the repository at this point in the history
  • Loading branch information
jeffreyvdhondel authored Dec 1, 2024
1 parent ca4ce30 commit 968cdb7
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
10 changes: 9 additions & 1 deletion docs/content/1.getting-started/4.configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@ export default defineNuxtConfig({
onlyOperationTypes: true,
avoidOptionals: false,
disableOnBuild: false,
maybeValue: 'T | null'
maybeValue: 'T | null',
scalars: {}
}
}
})
Expand Down Expand Up @@ -128,6 +129,13 @@ Disable Code Generation for production builds.

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

### `scalars`

- default: `{}`

Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type. See [GraphQL Code Generator documentation](https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#scalars) 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 @@ -50,7 +50,8 @@ function prepareConfig(options: GenerateOptions & GqlCodegen): CodegenConfig {
enumValues: 'change-case-all#upperCaseFirst'
},
avoidOptionals: options?.avoidOptionals,
maybeValue: options?.maybeValue
maybeValue: options?.maybeValue,
scalars: options?.scalars
}

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 @@ -52,7 +52,8 @@ export default defineNuxtModule<GqlConfig>({
disableOnBuild: false,
onlyOperationTypes: true,
avoidOptionals: false,
maybeValue: 'T | null'
maybeValue: 'T | null',
scalars: {}
}

config.codegen = !!config.codegen && defu<GqlCodegen, [GqlCodegen]>(config.codegen, codegenDefaults)
Expand Down
6 changes: 6 additions & 0 deletions src/types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,12 @@ export interface GqlCodegen {
(https://the-guild.dev/graphql/codegen/plugins/typescript/typescript-operations#maybevalue)
*/
maybeValue?: string

/**
* Extends or overrides the built-in scalars and custom GraphQL scalars to a custom type.
(https://the-guild.dev/graphql/codegen/plugins/typescript/typescript#scalars
*/
scalars?: string | { [name: string]: string | { input: string, output: string } }
}

export interface GqlConfig<T = GqlClient> {
Expand Down

0 comments on commit 968cdb7

Please sign in to comment.