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

dont change files when there are ts errors #56

Merged
merged 1 commit into from
Jun 2, 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/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