Mirror: TypeScript LSP plugin that finds GraphQL documents in your code and provides diagnostics, auto-complete and hover-information.

guard against missing schema or errors in codegen (#89)

Changed files
+15 -4
.changeset
packages
graphqlsp
+5
.changeset/quick-tips-promise.md
···
+
---
+
'@0no-co/graphqlsp': patch
+
---
+
+
Guard against no schema or errored codegen attempts
+3 -1
packages/graphqlsp/src/diagnostics.ts
···
texts.join('\n'),
scalars,
baseTypesPath
-
).then(() => {
+
).then(({ success }) => {
+
if (!success) return undefined;
+
source = getSource(info, filename);
if (!source) return undefined;
+7 -3
packages/graphqlsp/src/graphql/generateTypes.ts
···
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();
···
fs.writeFile(path.join(outputFile), output, 'utf8', err => {
console.error(err);
});
-
} catch (e) {}
+
+
return { success: true };
+
} catch (e) {
+
return { success: false };
+
}
};