diff --git a/.changeset/fluffy-apples-eat.md b/.changeset/fluffy-apples-eat.md new file mode 100644 index 00000000..a5706d95 --- /dev/null +++ b/.changeset/fluffy-apples-eat.md @@ -0,0 +1,5 @@ +--- +'@0no-co/graphqlsp': patch +--- + +dont perform file additions when we have ts-errors diff --git a/packages/example/src/Pokemon.ts b/packages/example/src/Pokemon.ts index 0ee516f0..4d26ecbc 100644 --- a/packages/example/src/Pokemon.ts +++ b/packages/example/src/Pokemon.ts @@ -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( _fragment: TypedDocumentNode, data: any diff --git a/packages/graphqlsp/src/diagnostics.ts b/packages/graphqlsp/src/diagnostics.ts index 9b0c3095..15139f7b 100644 --- a/packages/graphqlsp/src/diagnostics.ts +++ b/packages/graphqlsp/src/diagnostics.ts @@ -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 }, @@ -263,7 +266,7 @@ export function getGraphQLDiagnostics( scalars, baseTypesPath ).then(() => { - if (isFileDirty(filename, source)) { + if (isFileDirty(filename, source) && !hasTSErrors) { return; } diff --git a/packages/graphqlsp/src/index.ts b/packages/graphqlsp/src/index.ts index cf3fcec5..03bbf399 100644 --- a/packages/graphqlsp/src/index.ts +++ b/packages/graphqlsp/src/index.ts @@ -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;