Skip to content

Commit b7c24f6

Browse files
authored
guard against missing schema or errors in codegen (#89)
1 parent 313cb3b commit b7c24f6

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

.changeset/quick-tips-promise.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@0no-co/graphqlsp': patch
3+
---
4+
5+
Guard against no schema or errored codegen attempts

packages/graphqlsp/src/diagnostics.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,9 @@ export function getGraphQLDiagnostics(
309309
texts.join('\n'),
310310
scalars,
311311
baseTypesPath
312-
).then(() => {
312+
).then(({ success }) => {
313+
if (!success) return undefined;
314+
313315
source = getSource(info, filename);
314316
if (!source) return undefined;
315317

packages/graphqlsp/src/graphql/generateTypes.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ export const generateTypedDocumentNodes = async (
5959
doc: string,
6060
scalars: Record<string, unknown>,
6161
baseTypesPath: string
62-
) => {
62+
): Promise<{ success: boolean }> => {
6363
try {
64-
if (!schema) return;
64+
if (!schema) return { success: false };
6565

6666
const parts = outputFile.split('/');
6767
parts.pop();
@@ -106,5 +106,9 @@ export const generateTypedDocumentNodes = async (
106106
fs.writeFile(path.join(outputFile), output, 'utf8', err => {
107107
console.error(err);
108108
});
109-
} catch (e) {}
109+
110+
return { success: true };
111+
} catch (e) {
112+
return { success: false };
113+
}
110114
};

0 commit comments

Comments
 (0)