Skip to content

Commit deb53c7

Browse files
feat: update type imports and enhance Nuxt module setup for better type handling
1 parent f79b4cf commit deb53c7

File tree

4 files changed

+14
-8
lines changed

4 files changed

+14
-8
lines changed

playground-nuxt/app/graphql/sdk.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* tslint:disable */
44
/* eslint-disable */
55
/* prettier-ignore */
6-
import * as Types from '#graphql/client';
6+
import type * as Types from '#graphql/client';
77

88
export type CreateUserMutationVariables = Types.Exact<{
99
input: Types.CreateUserInput;

src/client-codegen.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,11 @@ export async function generateClientTypes(
162162
NonEmptyString: 'string',
163163
Currency: 'string',
164164
},
165+
useTypeImports: true,
166+
165167
},
166168
presetConfig: {
167169
typesPath: '#graphql/client',
168-
169170
},
170171
plugins: [
171172
{ pluginContent: {} },

src/ecosystem/nuxt.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { VueTSConfig } from '@nuxt/schema'
2-
import { addImportsDir, defineNuxtModule } from '@nuxt/kit'
3-
import { join } from 'pathe'
2+
import { defineNuxtModule } from '@nuxt/kit'
3+
import { join, resolve } from 'pathe'
44

55
export interface ModuleOptions {
66

@@ -14,8 +14,7 @@ export default defineNuxtModule<ModuleOptions>({
1414
nuxt: '>=3.16.0',
1515
},
1616
},
17-
defaults: {},
18-
setup: (options, nuxt) => {
17+
setup: async (_options, nuxt) => {
1918
nuxt.hooks.hook('prepare:types', (options) => {
2019
options.references.push({ path: 'types/nitro-graphql-client.d.ts' })
2120

@@ -33,6 +32,8 @@ export default defineNuxtModule<ModuleOptions>({
3332
nuxt.options.alias = nuxt.options.alias || {}
3433
nuxt.options.alias['#graphql/client'] = join(nuxt.options.buildDir, 'types/nitro-graphql-client.d.ts')
3534

36-
addImportsDir(join(nuxt.options.srcDir, 'graphql'))
35+
nuxt.hook('imports:dirs', (dirs) => {
36+
dirs.push(resolve(nuxt.options.srcDir, 'graphql'))
37+
})
3738
},
3839
})

src/index.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export default defineNitroModule({
3131
default:
3232
}
3333

34-
watch(watchDirs, {
34+
const watcher = watch(watchDirs, {
3535
persistent: true,
3636
ignoreInitial: true,
3737
ignored: nitro.options.ignore,
@@ -41,6 +41,10 @@ export default defineNitroModule({
4141
}
4242
})
4343

44+
nitro.hooks.hook('close', () => {
45+
watcher.close()
46+
})
47+
4448
const tsConfigPath = resolve(
4549
nitro.options.buildDir,
4650
nitro.options.typescript.tsconfigPath,

0 commit comments

Comments
 (0)