Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent duplicate file generation #100

Merged
merged 1 commit into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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