File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55 generate ,
66 loadContext ,
77} from '@graphql-codegen/cli' ;
8- import { isCodegenConfig } from './utils/fileMatchers' ;
8+ import { isCodegenConfig , isGeneratedFile } from './utils/fileMatchers' ;
99import { isBuildMode , isServeMode , type ViteMode } from './utils/viteModes' ;
1010import { debugLog } from './utils/debugLog' ;
1111import { createMatchCache } from './utils/matchCache' ;
@@ -221,6 +221,11 @@ export function GraphQLCodegen(options?: Options): Plugin {
221221 server . watcher . on ( 'add' , async ( filePath ) => {
222222 log ( `File added: ${ filePath } ` ) ;
223223
224+ if ( isGeneratedFile ( filePath , codegenContext ) ) {
225+ log ( 'File is a generated output file, skipping' ) ;
226+ return ;
227+ }
228+
224229 try {
225230 log ( 'Match cache refreshing' ) ;
226231 await matchCache . refresh ( ) ;
Original file line number Diff line number Diff line change @@ -16,7 +16,7 @@ export async function getDocumentPaths(
1616 }
1717
1818 const normalized = sourceDocuments
19- . filter ( ( item ) : item is NonNullable < typeof item > => ! ! item )
19+ . filter ( ( item ) => item !== undefined )
2020 . flat ( ) ;
2121
2222 if ( ! normalized . length ) return [ ] ;
@@ -60,3 +60,9 @@ export async function getSchemaPaths(
6060 . filter ( Boolean )
6161 . map ( normalizePath ) ;
6262}
63+
64+ export function getGeneratesPaths ( context : CodegenContext ) : string [ ] {
65+ const config = context . getConfig ( ) ;
66+
67+ return Object . keys ( config . generates ) . map ( normalizePath ) ;
68+ }
Original file line number Diff line number Diff line change 11import { normalizePath } from 'vite' ;
22import type { CodegenContext } from '@graphql-codegen/cli' ;
3+ import { getGeneratesPaths } from './configPaths' ;
34
45export function isCodegenConfig ( filePath : string , context : CodegenContext ) {
56 if ( ! context . filepath ) return false ;
67
78 return normalizePath ( filePath ) === normalizePath ( context . filepath ) ;
89}
10+
11+ export function isGeneratedFile ( filePath : string , context : CodegenContext ) {
12+ const generatesPaths = getGeneratesPaths ( context ) ;
13+
14+ const normalizedFilePath = normalizePath ( filePath ) ;
15+
16+ return generatesPaths . some ( ( path ) => normalizedFilePath . includes ( path ) ) ;
17+ }
You can’t perform that action at this time.
0 commit comments