Skip to content

Commit

Permalink
prevent dupes
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Sep 17, 2023
1 parent 7a3817b commit 2ba2149
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changeset/popular-bikes-clap.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Prevent duplicate async file-generation processes from happening
7 changes: 6 additions & 1 deletion packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ export const MISSING_OPERATION_NAME_CODE = 52002;
export const MISSING_FRAGMENT_CODE = 52003;
export const USING_DEPRECATED_FIELD_CODE = 52004;

let isGeneratingTypes = false;

export function getGraphQLDiagnostics(
// This is so that we don't change offsets when there are
// TypeScript errors
Expand Down Expand Up @@ -308,9 +310,10 @@ export function getGraphQLDiagnostics(
!disableTypegen
) {
try {
if (isFileDirty(filename, source)) {
if (isFileDirty(filename, source) && !isGeneratingTypes) {
return tsDiagnostics;
}
isGeneratingTypes = true;

const parts = source.fileName.split('/');
const name = parts[parts.length - 1];
Expand Down Expand Up @@ -421,10 +424,12 @@ export function getGraphQLDiagnostics(
info.languageServiceHost.writeFile!(source.fileName, finalSourceText);
scriptInfo!.reloadFromFile();
scriptInfo!.registerFileUpdate();
isGeneratingTypes = false;
});
} catch (e) {
const scriptInfo = info.project.projectService.getScriptInfo(filename);
scriptInfo!.reloadFromFile();
isGeneratingTypes = false;
}
}

Expand Down

0 comments on commit 2ba2149

Please sign in to comment.