@@ -60,10 +60,29 @@ interface PendingChanges {
6060 * Watches for changes and triggers type regeneration and dev server reload
6161 */
6262export function setupFileWatcher ( nitro : Nitro , watchDirs : string [ ] ) : FSWatcher {
63+ // Only watch graphql-related files, ignore everything else
64+ const ignored = ( path : string ) => {
65+ // Always ignore these directories
66+ if ( path . includes ( '/node_modules/' ) || path . includes ( '/.git/' )
67+ || path . includes ( '/.output/' ) || path . includes ( '/.nitro/' )
68+ || path . includes ( '/.nuxt/' ) || path . includes ( '/.graphql/' ) ) {
69+ return true
70+ }
71+ // Check if it's a directory (no extension or ends with /) - allow traversal
72+ if ( ! path . includes ( '.' ) || path . endsWith ( '/' ) ) {
73+ return false
74+ }
75+ // Only watch graphql, resolver, and directive files
76+ const isGraphQL = GRAPHQL_EXTENSIONS . some ( ext => path . endsWith ( ext ) )
77+ const isResolver = RESOLVER_EXTENSIONS . some ( ext => path . endsWith ( ext ) )
78+ const isDirective = DIRECTIVE_EXTENSIONS . some ( ext => path . endsWith ( ext ) )
79+ return ! isGraphQL && ! isResolver && ! isDirective
80+ }
81+
6382 const watcher = watch ( watchDirs , {
6483 persistent : DEFAULT_WATCHER_PERSISTENT ,
6584 ignoreInitial : DEFAULT_WATCHER_IGNORE_INITIAL ,
66- ignored : nitro . options . ignore ,
85+ ignored,
6786 } )
6887
6988 const pending : PendingChanges = { server : false , client : false , graphql : false }
@@ -76,17 +95,12 @@ export function setupFileWatcher(nitro: Nitro, watchDirs: string[]): FSWatcher {
7695 const directivesResult = await NitroAdapter . scanDirectives ( nitro )
7796 nitro . scanDirectives = directivesResult . items
7897
79- if ( ! nitro . scanSchemas )
80- nitro . scanSchemas = [ ]
98+ // Generate directive schemas and write to .graphql/directives.graphql
99+ const directiveSchemas = await generateDirectiveSchemas ( directivesResult . items , nitro . graphql . buildDir )
100+ nitro . graphql . directiveSchemas = directiveSchemas
81101
82- const directivesPath = await generateDirectiveSchemas ( nitro , directivesResult . items )
83102 const schemasResult = await NitroAdapter . scanSchemas ( nitro )
84- const schemas = schemasResult . items
85-
86- if ( directivesPath && ! schemas . includes ( directivesPath ) )
87- schemas . push ( directivesPath )
88-
89- nitro . scanSchemas = schemas
103+ nitro . scanSchemas = schemasResult . items
90104 nitro . scanResolvers = ( await NitroAdapter . scanResolvers ( nitro ) ) . items
91105
92106 await resolveExtendConfig ( nitro , { silent : true } )
0 commit comments