Skip to content

Commit

Permalink
guard against missing schema or errors in codegen (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock authored Jun 27, 2023
1 parent 313cb3b commit b7c24f6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/quick-tips-promise.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

Guard against no schema or errored codegen attempts
4 changes: 3 additions & 1 deletion packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,9 @@ export function getGraphQLDiagnostics(
texts.join('\n'),
scalars,
baseTypesPath
).then(() => {
).then(({ success }) => {
if (!success) return undefined;

source = getSource(info, filename);
if (!source) return undefined;

Expand Down
10 changes: 7 additions & 3 deletions packages/graphqlsp/src/graphql/generateTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,9 @@ export const generateTypedDocumentNodes = async (
doc: string,
scalars: Record<string, unknown>,
baseTypesPath: string
) => {
): Promise<{ success: boolean }> => {
try {
if (!schema) return;
if (!schema) return { success: false };

const parts = outputFile.split('/');
parts.pop();
Expand Down Expand Up @@ -106,5 +106,9 @@ export const generateTypedDocumentNodes = async (
fs.writeFile(path.join(outputFile), output, 'utf8', err => {
console.error(err);
});
} catch (e) {}

return { success: true };
} catch (e) {
return { success: false };
}
};

0 comments on commit b7c24f6

Please sign in to comment.