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

Is there an existing issue for this?

  • 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

About this issue

  • Original URL
  • State: open
  • Created 3 years ago
  • Reactions: 12
  • Comments: 24 (7 by maintainers)

Most upvoted comments

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.

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)

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

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)

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.

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

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!