graphiql
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
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
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.
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
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)
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!
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.
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)
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?
No, AFAIK.
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)
Still happening
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
Still having this issue on pre-release
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
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
@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
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.
@acao is there any update on this? It's still happening on the latest version. Downgrading is the only way to resolve this.
@Tadimsky I suspect this is due to changes where we let graphql config do more of the parsing. Looking into it still!