Skip to content

Commit

Permalink
dont change files when there are ts errors (#56)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoviDeCroock committed Jun 2, 2023
1 parent 49e1074 commit 951f987
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/fluffy-apples-eat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@0no-co/graphqlsp': patch
---

dont perform file additions when we have ts-errors
5 changes: 4 additions & 1 deletion packages/example/src/Pokemon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,15 @@ export const PokemonFields = gql`
}
}
` as typeof import('./Pokemon.generated').PokemonFieldsFragmentDoc;

export const Pokemon = (data: any) => {
const pokemon = useFragment(PokemonFields, data);
return `hi ${pokemon.name}`;
};

type X = { hello: string };

const x: X = { hello: '' };

export function useFragment<Type>(
_fragment: TypedDocumentNode<Type>,
data: any
Expand Down
5 changes: 4 additions & 1 deletion packages/graphqlsp/src/diagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export const MISSING_FRAGMENT_CODE = 52003;
export const USING_DEPRECATED_FIELD_CODE = 52004;

export function getGraphQLDiagnostics(
// This is so that we don't change offsets when there are
// TypeScript errors
hasTSErrors: Boolean,
filename: string,
baseTypesPath: string,
schema: { current: GraphQLSchema | null },
Expand Down Expand Up @@ -263,7 +266,7 @@ export function getGraphQLDiagnostics(
scalars,
baseTypesPath
).then(() => {
if (isFileDirty(filename, source)) {
if (isFileDirty(filename, source) && !hasTSErrors) {
return;
}

Expand Down
11 changes: 8 additions & 3 deletions packages/graphqlsp/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,21 @@ function create(info: ts.server.PluginCreateInfo) {
);

proxy.getSemanticDiagnostics = (filename: string): ts.Diagnostic[] => {
const originalDiagnostics =
info.languageService.getSemanticDiagnostics(filename);

if (originalDiagnostics.length) {
return originalDiagnostics;
}

const graphQLDiagnostics = getGraphQLDiagnostics(
originalDiagnostics.length > 0,
filename,
baseTypesPath,
schema,
info
);

const originalDiagnostics =
info.languageService.getSemanticDiagnostics(filename);

return graphQLDiagnostics
? [...graphQLDiagnostics, ...originalDiagnostics]
: originalDiagnostics;
Expand Down

0 comments on commit 951f987

Please sign in to comment.