graphiql icon indicating copy to clipboard operation
graphiql copied to clipboard

[lsp-server] 🐞 The language server throws "could not parse the TypeScript file" error for every TS file when `documents` field is used

Open HosseinAgha opened this issue 1 year ago • 20 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Current Behavior

The language server throws Could not parse the TypeScript file. SyntaxError: Unexpected token, expected "," errors when I use documents section in GraphQL config.
The Config:

projects:
  apps:
    schema: https://localhost:8080/graphql
    documents:
      - ./app/**/*.{ts,tsx}
      - '!(app/operations/generated/*)'
      - '!(app/operations/gqlApolloHooks.ts)'

The Other Config That I tested:

projects:
  apps:
    schema: https://localhost:8080/graphql
    documents:
      - ./app/**/*.{ts,tsx}
      - '!./app/operations/generated/*.{ts,tsx}'
      - '!./app/operations/gqlApolloHooks.ts'

And here is a trick config that works:

projects:
  apps:
    schema: https://localhost:8080/graphql
    include:
      - ./app/**/*.{ts,tsx}
    exclude:
      - './app/operations/generated/*.{ts,tsx}'
      - './app/operations/gqlApolloHooks.ts'

Expected Behavior

It should not throw TypeScript errors and just work.

Steps To Reproduce

No response

Environment

  • LSP Server Version: VSCode GraphQL v0.8.17
  • OS: macos

Anything else?

No response

HosseinAgha avatar Aug 28 '23 16:08 HosseinAgha

Looks like my GraphQL schema did not load correctly, I switched back to using documents because fragments did not work with include.
The LSP is still throwing TypeScript errors but everything magically works now.
I'll keep this issue open as I still get the errors. I'll change the issue title.

HosseinAgha avatar Aug 28 '23 17:08 HosseinAgha

I'm having the same error message in a monorepo setup with projects in the configuration. Every graphQL file throws the same "Could not parse the TypeScript file" error and after some time the GraphQL server crashes too often so it won't automatically restart

TheMaru avatar Sep 05 '23 10:09 TheMaru

I'm seeing the same problem

Could not parse the TypeScript file at [path to .tsx] to extract the graphql tags:
SyntaxError: Unexpected token, expected "," (1:33)

Akkuma avatar Sep 20 '23 12:09 Akkuma

i believed the fix for this is released as v0.8.19 for vscode-graphql, 2.11.5 for the LSP, let me know if that helps!

acao avatar Sep 26 '23 21:09 acao

Nope still getting SyntaxError: Unexpected token, expected "," errors in the graphql language server output everytime I reload the VSCode. (All my queries are defined using gql-tag inside ts files) The autocomplete works fine though.

HosseinAgha avatar Sep 30 '23 10:09 HosseinAgha

I'm getting the same thing:

[Error - 11:22:11 PM] Could not parse the TypeScript file at file:///Users/jonno/Source/dorado/components/generic/CarrierAsyncSelect.tsx to extract the graphql tags:
[Error - 11:22:11 PM] SyntaxError: Unexpected token, expected "," (1:48)

Tadimsky avatar Oct 19 '23 06:10 Tadimsky

ok, i think this is related to using graphql config to parse files again, which we reintroduced a few months ago. graphql config throws errors when a file is not perfectly parsable, whereas autocomplete and hover and other features use our fault tolerant parser. are any features besides validation not working because of these errors?

acao avatar Oct 19 '23 08:10 acao

No, AFAIK.

HosseinAgha avatar Nov 08 '23 13:11 HosseinAgha

Same issue here with the following config:

// graphql.config.ts
import type { IGraphQLConfig } from 'graphql-config'

const schema = 'apps/api/src/schema/**/*.graphql'

export default {
  projects: {
    api: {
      schema,
    },
    web: {
      documents: 'apps/web/src/**/*.{ts,tsx}',
      schema,
    },
  },
} satisfies IGraphQLConfig

and the following output:

[Error - 02:54:29] Could not parse the TypeScript file at file:///some/file/path/etc.ts to extract the graphql tags:
[Error - 02:54:29] SyntaxError: Unexpected token, expected "," (1:28)

lensbart avatar Dec 13 '23 01:12 lensbart

Still happening

Daniel3711997 avatar Mar 22 '24 09:03 Daniel3711997

most of these issues will be fixed in the next minor release soon! the errors do not point to the exact cause. documents config will be required and a warning will be logged if it isn't present. I plan to release this this weekend after adding more integration specs and manual testing.

and then another major release will occur - this is another major rewrite which ensures that graphql-config includes and excludes are honored. this 2nd refactor actually just uses @graphql-tools/load to properly do everything with graphql config pointers, instead of manually unwrapping the pointers like we do now. we have been planning this with the guild for a long time! and so far it is much faster.

keep an eye out for the pre-release channel, and v0.10.1 or so

acao avatar Mar 22 '24 23:03 acao

Still having this issue on pre-release

addiebarron avatar Apr 19 '24 20:04 addiebarron

unfortunately the issue will continue happening until the 2nd stage rewrite, as it comes from graphql tools loadTypeDefs() via graphql config loadConfig(). it doesn't mean anything though because it falls back to another parser and keeps going

in the next release, where we overhaul logging levels, these errors will be buried because they are not relevant

acao avatar Apr 21 '24 09:04 acao

I encountered a similar issue with the latest version (v0.11.0) where all my fragments are reported as "Unknown". Downgrading the extension to v0.9.3 fixes the issue.

However, both versions show the following errors for every TypeScript files in my repo:

[Error - 10:51:46 AM] Could not parse the TypeScript file at file:///xxx.tsx to extract the graphql tags:
[Error - 10:51:46 AM] SyntaxError: Unexpected token, expected "," (1:24)

Not sure why v0.9.3 works correctly and go to definition for fragments also works.

luin avatar Jun 04 '24 02:06 luin

same issue

lucas-garrido avatar Jun 04 '24 09:06 lucas-garrido

@luin these errors are unrelated. in the latest graphql config version it seems you must use arrays if you want full paths for documents, otherwise use globs for documents config

acao avatar Jun 04 '24 10:06 acao

I encountered a similar issue with the latest version (v0.11.0) where all my fragments are reported as "Unknown". Downgrading the extension to v0.9.3 fixes the issue.

However, both versions show the following errors for every TypeScript files in my repo:

[Error - 10:51:46 AM] Could not parse the TypeScript file at file:///xxx.tsx to extract the graphql tags:
[Error - 10:51:46 AM] SyntaxError: Unexpected token, expected "," (1:24)

Not sure why v0.9.3 works correctly and go to definition for fragments also works.

Yes downgrading works for me as well. I am having this issue with all of my .vue files in my project.

bensoutendijk avatar Jun 11 '24 15:06 bensoutendijk

@acao is there any update on this? It's still happening on the latest version. Downgrading is the only way to resolve this.

Tadimsky avatar Aug 01 '24 15:08 Tadimsky

@Tadimsky I suspect this is due to changes where we let graphql config do more of the parsing. Looking into it still!

acao avatar Aug 04 '24 05:08 acao